Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
84736c6
fix(instance): ensure proper disposal of current units in UniverInsta…
siam-ese Dec 5, 2025
2a8b9d3
fix(workbook): ensure proper cleanup of worksheets during disposal
siam-ese Dec 5, 2025
1e355ae
fix(table-manager): ensure complete disposal of observables during cl…
siam-ese Dec 6, 2025
43eb54c
fix(instance): ensure proper disposal of units in TableManager during…
siam-ese Dec 6, 2025
9a7f814
refactor(table-manager): remove redundant unit disposal logging in Ta…
siam-ese Dec 6, 2025
1bb7751
fix(table-manager): ensure proper disposal of units in deleteUnitId m…
siam-ese Dec 6, 2025
fa08799
fix(instance): add logging for unit addition and disposal in UniverIn…
hexf00 Dec 6, 2025
170cee9
fix(instance): add debug logging for unit disposal when no unit is found
hexf00 Dec 6, 2025
d64f1bf
fix(instance): add debug logging for WebWorkerRemoteInstanceService
hexf00 Dec 6, 2025
4c7a60e
refactor(table-manager): remove unused logging service from TableMana…
siam-ese Dec 6, 2025
10561bd
refactor(rpc.service): simplify request handling by destructuring _pe…
siam-ese Dec 6, 2025
22d67b5
fix(plugin): add execArgv for child process to enable debugging
hexf00 Dec 6, 2025
1a1206c
Revert "fix(plugin): add execArgv for child process to enable debugging"
hexf00 Dec 6, 2025
804d7f6
fix: eslint error
siam-ese Dec 8, 2025
74d283a
fix: does not delete handler at next type of response
siam-ese Dec 8, 2025
1ae67f3
fix(workbook): defer clearing worksheets until after disposal completes
siam-ese Dec 8, 2025
35ab342
Merge branch 'dev' into fix/dispose-unit
siam-ese Dec 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/core/src/services/instance/instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Workbook } from '../../sheets/workbook';
import { SlideDataModel } from '../../slides/slide-model';
import { FOCUSING_DOC, FOCUSING_SHEET, FOCUSING_SLIDE, FOCUSING_UNIT } from '../context/context';
import { IContextService } from '../context/context.service';
import { ILogService } from '../log/log.service';

// eslint-disable-next-line ts/no-explicit-any
export type UnitCtor = new (...args: any[]) => UnitModel;
Expand Down Expand Up @@ -107,7 +108,8 @@ export class UniverInstanceService extends Disposable implements IUniverInstance

constructor(
@Inject(Injector) private readonly _injector: Injector,
@IContextService private readonly _contextService: IContextService
@IContextService private readonly _contextService: IContextService,
@Inject(ILogService) private readonly _logService: ILogService
) {
super();
}
Expand All @@ -118,6 +120,8 @@ export class UniverInstanceService extends Disposable implements IUniverInstance
this._focused$.complete();
this._currentUnits$.complete();
this._unitAdded$.complete();

this._currentUnits.forEach((unit) => unit?.dispose());
this._currentUnits.clear();
this._unitsByType.clear();
}
Expand Down Expand Up @@ -186,6 +190,7 @@ export class UniverInstanceService extends Disposable implements IUniverInstance
* @param unit The unit to be added.
*/
__addUnit(unit: UnitModel, options?: ICreateUnitOptions): void {
this._logService.debug(`[UniverInstanceService]: Adding unit with id ${unit.getUnitId()}`);
const type = unit.type;

if (!this._unitsByType.has(type)) {
Expand Down Expand Up @@ -296,19 +301,26 @@ export class UniverInstanceService extends Disposable implements IUniverInstance
}

disposeUnit(unitId: string): boolean {
this._logService.debug(`[UniverInstanceService]: Disposing unit with id ${unitId}`);
const result = this._getUnitById(unitId);
if (!result) return false;
if (!result) {
this._logService.debug(`[UniverInstanceService]: No unit found with id ${unitId}`);
return false;
}

const [unit, type] = result;
const units = this._unitsByType.get(type)!;
const index = units.indexOf(unit);

units.splice(index, 1);

this._tryResetCurrentOnRemoval(unitId, type);
this._tryResetFocusOnRemoval(unitId);

this._unitDisposed$.next(unit);

unit.dispose();

return true;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/sheets/workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVER
this._sheetDisposed$.complete();
this._activeSheet$.complete();
this._name$.complete();

Promise.resolve().then(() => {
this._worksheets.clear();
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class WebWorkerRemoteInstanceService implements IRemoteInstanceService {
type: UniverInstanceType;
snapshot: IWorkbookData;
}): Promise<boolean> {
this._logService.debug(`[WebWorkerRemoteInstanceService]: Creating instance with id ${params.unitID}`);
const { type, snapshot } = params;
try {
switch (type) {
Expand All @@ -106,6 +107,7 @@ export class WebWorkerRemoteInstanceService implements IRemoteInstanceService {
}

async disposeInstance(params: { unitID: string }): Promise<boolean> {
this._logService.debug(`[WebWorkerRemoteInstanceService]: Disposing instance with id ${params.unitID}`);
return this._univerInstanceService.disposeUnit(params.unitID);
}

Expand Down
10 changes: 7 additions & 3 deletions packages/rpc/src/services/rpc/rpc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,21 @@ export class ChannelClient extends RxDisposable implements IChannelClient {
}

private _onMessage(response: IRPCResponse): void {
switch (response.type) {
const { type: responseType, seq } = response;
switch (responseType) {
case ResponseType.INITIALIZE:
this._initialized.next(true);
break;
case ResponseType.CALL_SUCCESS:
case ResponseType.CALL_FAILURE:
case ResponseType.SUBSCRIBE_NEXT:
case ResponseType.SUBSCRIBE_COMPLETE:
case ResponseType.SUBSCRIBE_ERROR:
this._pendingRequests.get(response.seq)?.handle(response);
case ResponseType.SUBSCRIBE_ERROR: {
const { _pendingRequests } = this;
_pendingRequests.get(seq)?.handle(response);
responseType !== ResponseType.SUBSCRIBE_NEXT && _pendingRequests.delete(seq);
break;
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions packages/sheets-table/src/model/table-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,24 @@ export class TableManager extends Disposable {
}

deleteUnitId(unitId: string) {
const unitMap = this._tableMap.get(unitId);
if (unitMap) {
unitMap.forEach((table) => table.dispose());
}
this._tableMap.delete(unitId);
}

override dispose() {
super.dispose();

this._tableAdd$.complete();
this._tableDelete$.complete();
this._tableNameChanged$.complete();
this._tableRangeChanged$.complete();
this._tableThemeChanged$.complete();
this._tableFilterChanged$.complete();
this._tableInitStatus.complete();

this._tableMap.forEach((unitMap) => {
unitMap.forEach((table) => table.dispose());
unitMap.clear();
Expand Down