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: lifecycle event handling in plugin holder (#2244)
Wenzhao Hu85af642046fe
diff --git a/packages/core/src/services/lifecycle/lifecycle.service.ts b/packages/core/src/services/lifecycle/lifecycle.service.tsindex e4d1ccfabf..cc75848deb 100644--- a/packages/core/src/services/lifecycle/lifecycle.service.ts+++ b/packages/core/src/services/lifecycle/lifecycle.service.ts@@ -92,7 +92,13 @@ export class LifecycleService extends Disposable {subscriber.next(LifecycleStages.Rendered);}- return this._lifecycle$.subscribe(subscriber);+ this._lifecycle$.subscribe((stage) => {+ subscriber.next(stage);++ if (stage === LifecycleStages.Steady) {+ subscriber.complete();+ }+ });});}diff --git a/packages/core/src/services/plugin/plugin-holder.ts b/packages/core/src/services/plugin/plugin-holder.tsindex d72faaad2b..590c75b751 100644--- a/packages/core/src/services/plugin/plugin-holder.ts+++ b/packages/core/src/services/plugin/plugin-holder.ts@@ -16,8 +16,10 @@/* eslint-disable ts/no-explicit-any */-import { type Ctor, Inject, Injector } from '@wendellhu/redi';+import type { Ctor } from '@wendellhu/redi';+import { Inject, Injector } from '@wendellhu/redi';+import { finalize } from 'rxjs';import { LifecycleStages } from '../lifecycle/lifecycle';import { LifecycleInitializerService, LifecycleService } from '../lifecycle/lifecycle.service';import { Disposable } from '../../shared/lifecycle';@@ -74,12 +76,11 @@ export class PluginHolder extends Disposable {const plugins = this._pluginRegistry.getRegisterPlugins().map(({ plugin, options }) => this._initPlugin(plugin, options));this._pluginRegistry.removePlugins();- const lifecycleSubscription = this.disposeWithMe(this._lifecycleService.subscribeWithPrevious().subscribe((stage) => {- this._pluginsRunLifecycle(plugins, stage);- if (stage === LifecycleStages.Steady) {- lifecycleSubscription.dispose();- }- }));+ const subscription = this.disposeWithMe(this._lifecycleService.subscribeWithPrevious()+ // It has to been async because the finalize may execute synchronously after we+ // make the subscription. For example, the lifecycle service is already in stage "steady".+ .pipe(finalize(() => { Promise.resolve().then(() => subscription.dispose()); }))+ .subscribe((stage) => { this._pluginsRunLifecycle(plugins, stage); }));}diff --git a/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts b/packages/sheets-ui/src/services/sheet-skeleton-manager.service.tsindex f40a41f426..73f3f62db7 100644--- a/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts+++ b/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts@@ -93,6 +93,9 @@ export class SheetSkeletonManagerService implements IDisposable {removeSkeleton(searchParam: Pick<ISheetSkeletonManagerSearch, 'unitId'>) {const index = this._sheetSkeletonParam.findIndex((param) => param.unitId === searchParam.unitId);if (index !== -1) {+ const skeletonParam = this._sheetSkeletonParam[index];+ skeletonParam.skeleton.dispose();+this._sheetSkeletonParam.splice(index, 1);this._currentSkeletonBefore$.next(null);this._currentSkeleton$.next(null);