Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(network): work in ancestor env (#4296)
Wenzhao Hu2502caf05a03
diff --git a/packages/core/package.json b/packages/core/package.jsonindex e50e6eef32..108eaa502f 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -63,7 +63,7 @@},"dependencies": {"@univerjs/protocol": "0.1.39",- "@wendellhu/redi": "0.16.1",+ "@wendellhu/redi": "0.16.2","dayjs": "^1.11.13","fast-diff": "1.3.0","kdbush": "^4.0.2",diff --git a/packages/network/src/plugin.ts b/packages/network/src/plugin.tsindex cb2f1321de..b972e3007b 100644--- a/packages/network/src/plugin.ts+++ b/packages/network/src/plugin.ts@@ -15,11 +15,11 @@*/import type { DependencyOverride } from '@univerjs/core';-import { Inject, Injector, mergeOverrideWithDependencies, Plugin, registerDependencies } from '@univerjs/core';+import { ILogService, Inject, Injector, LookUp, mergeOverrideWithDependencies, Plugin, Quantity, registerDependencies } from '@univerjs/core';import { HTTPService } from './services/http/http.service';+import { FetchHTTPImplementation } from './services/http/implementations/fetch';import { IHTTPImplementation } from './services/http/implementations/implementation';import { XHRHTTPImplementation } from './services/http/implementations/xhr';-import { FetchHTTPImplementation } from './services/http/implementations/fetch';export interface IUniverNetworkPluginConfig {/**@@ -34,6 +34,12 @@ export interface IUniverNetworkPluginConfig {* - {@link IHTTPImplementation}*/override?: DependencyOverride;++ /**+ * Force to use a new instance of {@link HTTPService} and {@link IHTTPImplementation} even if+ * an ancestor injector already has them registered.+ */+ forceUseNewInstance?: boolean;}/**@@ -44,12 +50,23 @@ export class UniverNetworkPlugin extends Plugin {constructor(private readonly _config: Partial<IUniverNetworkPluginConfig> | undefined = undefined,+ @ILogService private readonly _logger: ILogService,@Inject(Injector) protected readonly _injector: Injector) {super();}override onStarting(): void {+ const parent = this._injector.get(HTTPService, Quantity.OPTIONAL, LookUp.SKIP_SELF);+ if (parent && !this._config?.forceUseNewInstance) {+ this._logger.warn(+ '[UniverNetworkPlugin]',+ 'HTTPService is already registered in an ancestor interceptor. Skipping registration. ' ++ 'If you want to force a new instance, set "forceUseNewInstance" to true in the plugin configuration.'+ );+ return;+ }+const impl = this._config?.useFetchImpl? FetchHTTPImplementation: typeof window !== 'undefined'diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 92b828b4a4..d42b9c4237 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1055,8 +1055,8 @@ importers:specifier: 0.1.39version: 0.1.39(@grpc/[email protected])([email protected])'@wendellhu/redi':- specifier: 0.16.1- version: 0.16.1+ specifier: 0.16.2+ version: 0.16.2dayjs:specifier: ^1.11.13version: 1.11.13@@ -5489,8 +5489,8 @@ packages:'@webassemblyjs/[email protected]':resolution: {integrity: sha512-+X4WAlOisVWQMikjbcvY2e0rwPsKQ9F688lksZhBcPycBBuii3O7m8FACbDMWDojpAqvjIncrG8J0XHKyQfVeA==}- '@wendellhu/[email protected]':- resolution: {integrity: sha512-nwyKHCIbAgA7ZjhH6a49lVhe8oPFHjg4AtUHUSqdQgYNvHIFTbIWEbieS1pU0TMMHrff+mxGCGp3BZW14AvNsw==}+ '@wendellhu/[email protected]':+ resolution: {integrity: sha512-34VWdZbIqjus5gAQCRDEBYxwtSEg0yU3pa7hqu0Mgo/xAZ6KpHb5WF0E7H0f3NGW/LwLzxlKCduYPn3d9EUPMw==}'@xtuc/[email protected]':resolution: {integrity: sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==}@@ -12795,7 +12795,7 @@ snapshots:'@webassemblyjs/ast': 1.12.1'@xtuc/long': 4.2.2- '@wendellhu/[email protected]': {}+ '@wendellhu/[email protected]': {}'@xtuc/[email protected]': {}