Skip to content

Commit

Permalink
fix: sheet dispose cause scroll update scene size failed. (#3205)
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku authored Aug 27, 2024
1 parent c67fc66 commit 6e1a234
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
31 changes: 16 additions & 15 deletions packages/engine-render/src/render-manager/render-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface IRenderManagerService extends IDisposable {
/**
* add dep to _renderDependencies(type, dep)
* @param type
* @param depCtor
* @param dep
*/
registerRenderModule<T extends UnitModel>(type: UnitType, dep: Dependency<T>): IDisposable;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
private readonly _renderDisposed$ = new Subject<string>();
readonly disposed$ = this._renderDisposed$.asObservable();

get defaultEngine() {
get defaultEngine(): Engine {
if (!this._defaultEngine) {
this._defaultEngine = new Engine();
}
Expand All @@ -122,7 +122,7 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
super();
}

override dispose() {
override dispose(): void {
super.dispose();

this._renderMap.forEach((item) => this._disposeItem(item));
Expand Down Expand Up @@ -278,6 +278,7 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
scene,
isMainScene,
});
this._addRenderUnit(unitId, renderUnit);

// init deps
this._tryAddRenderDependencies(renderUnit, ctorOfDeps);
Expand All @@ -297,21 +298,21 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
return null;
},
} as IRender;
this._addRenderUnit(unitId, renderUnit);
}

this._addRenderUnit(unitId, renderUnit);
return renderUnit;
}

addRender(unitId: string, item: IRender) {
this._addRenderUnit(unitId, item);
addRender(unitId: string, renderUnit: IRender): void {
this._addRenderUnit(unitId, renderUnit);
}

private _addRenderUnit(unitId: string, item: IRender) {
this._renderMap.set(unitId, item);
private _addRenderUnit(unitId: string, renderUnit: IRender): void {
this._renderMap.set(unitId, renderUnit);
}

removeRender(unitId: string) {
removeRender(unitId: string): void {
const item = this._renderMap.get(unitId);
if (item != null) {
this._disposeItem(item);
Expand All @@ -320,21 +321,21 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
this._renderMap.delete(unitId);
}

has(unitId: string) {
has(unitId: string): boolean {
return this._renderMap.has(unitId);
}

setCurrent(unitId: string) {
setCurrent(unitId: string): void {
this._currentUnitId = unitId;

this._currentRender$.next(unitId);
}

getCurrent() {
getCurrent(): Nullable<IRender> {
return this._renderMap.get(this._currentUnitId);
}

getFirst() {
getFirst(): Nullable<IRender> {
return [...this.getRenderAll().values()][0];
}

Expand All @@ -347,11 +348,11 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
return this._renderMap.get(unitId);
}

getRenderAll() {
getRenderAll(): Map<string, IRender> {
return this._renderMap;
}

private _disposeItem(item: Nullable<IRender>, shouldDestroyEngine: boolean = true) {
private _disposeItem(item: Nullable<IRender>, shouldDestroyEngine: boolean = true): void {
if (item == null) {
return;
}
Expand Down
14 changes: 10 additions & 4 deletions packages/ui/src/controllers/ui/ui-desktop.controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import { connectInjector, Disposable, IConfigService, Inject, Injector, isInternalEditorID, LifecycleService, LifecycleStages, OnLifecycle, Optional, toDisposable } from '@univerjs/core';
import type { IDisposable } from '@univerjs/core';
import { connectInjector, Disposable, IConfigService, Inject, Injector, isInternalEditorID, IUniverInstanceService, LifecycleService, LifecycleStages, OnLifecycle, Optional, toDisposable } from '@univerjs/core';
import type { RenderUnit } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { IDisposable } from '@univerjs/core';
import { render as createRoot, unmount } from 'rc-util/lib/React/render';
import React from 'react';

Expand All @@ -32,9 +32,11 @@ const STEADY_TIMEOUT = 3000;

@OnLifecycle(LifecycleStages.Ready, DesktopUIController)
export class DesktopUIController extends Disposable {
private _steadyTimeout: NodeJS.Timeout;
constructor(
private readonly _config: IUniverUIConfig,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
@Inject(Injector) private readonly _injector: Injector,
@Inject(LifecycleService) private readonly _lifecycleService: LifecycleService,
@IUIPartsService private readonly _uiPartsService: IUIPartsService,
Expand All @@ -50,6 +52,10 @@ export class DesktopUIController extends Disposable {
}

private _bootstrapWorkbench(): void {
this.disposeWithMe(this._instanceSrv.unitDisposed$.subscribe(() => {
clearTimeout(this._steadyTimeout);
}));

this.disposeWithMe(
bootstrap(this._injector, this._config, (contentElement, containerElement) => {
if (this._layoutService) {
Expand Down Expand Up @@ -78,13 +84,13 @@ export class DesktopUIController extends Disposable {
}

this._lifecycleService.stage = LifecycleStages.Rendered;
setTimeout(() => this._lifecycleService.stage = LifecycleStages.Steady, STEADY_TIMEOUT);
this._steadyTimeout = setTimeout(() => this._lifecycleService.stage = LifecycleStages.Steady, STEADY_TIMEOUT);
}, 300);
})
);
}

private _initBuiltinComponents() {
private _initBuiltinComponents(): void {
this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FLOATING, () => connectInjector(CanvasPopup, this._injector)));
this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(FloatDom, this._injector)));
}
Expand Down

0 comments on commit 6e1a234

Please sign in to comment.