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(core): fix resource loader not work for created units (#2996)
Wenzhao Hu9df348dcf3ba
diff --git a/packages/core/src/services/resource-loader/resource-loader.service.ts b/packages/core/src/services/resource-loader/resource-loader.service.tsindex 25aa7bd5b7..bfc3f286ff 100644--- a/packages/core/src/services/resource-loader/resource-loader.service.ts+++ b/packages/core/src/services/resource-loader/resource-loader.service.ts@@ -23,6 +23,7 @@ import { IUniverInstanceService } from '../instance/instance.service';import { Disposable } from '../../shared/lifecycle';import { UniverInstanceType } from '../../common/unit';import type { DocumentDataModel } from '../../docs';+import { isInternalEditorID } from '../../common/const';import type { IResourceLoaderService } from './type';export class ResourceLoaderService extends Disposable implements IResourceLoaderService {@@ -75,25 +76,37 @@ export class ResourceLoaderService extends Disposable implements IResourceLoader};const allResourceHooks = this._resourceManagerService.getAllResourceHooks();- allResourceHooks.forEach((hook) => {- handleHookAdd(hook);- });+ allResourceHooks.forEach((hook) => handleHookAdd(hook));- this.disposeWithMe(this._resourceManagerService.register$.subscribe((hook) => {- handleHookAdd(hook);- }));+ this.disposeWithMe(this._resourceManagerService.register$.subscribe((hook) => handleHookAdd(hook)));this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {this._resourceManagerService.loadResources(workbook.getUnitId(), workbook.getSnapshot().resources);}));+ this.disposeWithMe(+ this._univerInstanceService.getTypeOfUnitAdded$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC).subscribe((doc) => {+ const unitId = doc.getUnitId();+ if (!isInternalEditorID(unitId)) {+ this._resourceManagerService.loadResources(doc.getUnitId(), doc.getSnapshot().resources);+ }+ })+ );++ // TODO: add slides in the futurethis.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {this._resourceManagerService.unloadResources(workbook.getUnitId());}));++ this.disposeWithMe(+ this._univerInstanceService.getTypeOfUnitDisposed$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC).subscribe(((doc) => {+ this._resourceManagerService.unloadResources(doc.getUnitId());+ }))+ );}saveWorkbook: (workbook: Workbook) => IWorkbookData = (workbook) => {diff --git a/packages/docs-ui/src/services/docs-render.service.ts b/packages/docs-ui/src/services/docs-render.service.tsindex 7d932f67fc..68f94a1789 100644--- a/packages/docs-ui/src/services/docs-render.service.ts+++ b/packages/docs-ui/src/services/docs-render.service.ts@@ -35,11 +35,12 @@ export class DocsRenderService extends RxDisposable {.pipe(takeUntil(this.dispose$)).subscribe((unitId) => this._createRenderWithId(unitId));+ this._instanceSrv.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)+ .forEach((documentModel) => this._createRenderer(documentModel));+this._instanceSrv.getTypeOfUnitAdded$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((doc) => this._createRenderer(doc));- this._instanceSrv.getAllUnitsForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)- .forEach((documentModel) => this._createRenderer(documentModel));this._instanceSrv.getTypeOfUnitDisposed$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$))