From f8c1b663066910ab75a8afce1d83d10622995f08 Mon Sep 17 00:00:00 2001 From: hexf00 Date: Fri, 22 Mar 2024 16:30:09 +0800 Subject: [PATCH 1/2] fix: cleanup DOMs on dispose --- .../sheets-ui/src/services/clipboard/clipboard.service.ts | 4 ++++ .../sheets-ui/src/services/clipboard/html-to-usm/converter.ts | 4 ++++ packages/ui/src/views/App.tsx | 3 +++ 3 files changed, 11 insertions(+) diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts index 8cf61b6d338..a39d89a44ad 100644 --- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts +++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts @@ -116,6 +116,10 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard }); this._usmToHtml = new USMToHtmlService(); this._copyContentCache = new CopyContentCache(); + + this.disposeWithMe(toDisposable(() => { + this._htmlToUSM.dispose(); + })); } copyContentCache(): CopyContentCache { diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts index 5cd3b80a794..08a19dcb221 100644 --- a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts +++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts @@ -383,6 +383,10 @@ export class HtmlToUSMService { } } } + + dispose() { + document.body.removeChild(this.htmlElement); + } } /** diff --git a/packages/ui/src/views/App.tsx b/packages/ui/src/views/App.tsx index 5ed2365ffce..9a862f2c3fb 100644 --- a/packages/ui/src/views/App.tsx +++ b/packages/ui/src/views/App.tsx @@ -83,6 +83,9 @@ export function App(props: IUniverAppProps) { return () => { // batch unsubscribe subscriptions.forEach((subscription) => subscription.unsubscribe()); + + // cleanup + document.body.removeChild(portalContainer); }; }, [localeService, messageService, mountContainer, portalContainer, themeService.currentTheme$]); From 272c5640be8f9a13e45f6b73707d69bc484340be Mon Sep 17 00:00:00 2001 From: hexf00 Date: Fri, 22 Mar 2024 20:29:26 +0800 Subject: [PATCH 2/2] refactor(sheet-ui): simplified dispose Co-authored-by: Wenzhao Hu --- .../sheets-ui/src/services/clipboard/clipboard.service.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts index a39d89a44ad..e271384cc24 100644 --- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts +++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts @@ -117,9 +117,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard this._usmToHtml = new USMToHtmlService(); this._copyContentCache = new CopyContentCache(); - this.disposeWithMe(toDisposable(() => { - this._htmlToUSM.dispose(); - })); + this.disposeWithMe(this._htmlToUSM); } copyContentCache(): CopyContentCache {