Change:
Issue Type: <bBug</bRepro a notebook in the diff view (tested with the github issues notebook) down to another file bug In dev tools, see: VS Code version: Code - OSS Dev 1.55.0 (Commit unknown, Date unknown) OS version: Darwin x64 20.3.0 <details<summarySystem Info</summary </details<details<summaryExtensions (23)</summaryExtensionVersion ------ docs-view0.0.9 vscode-eslint2.1.14 EditorConfig0.16.4 vscode-pull-request-github0.23.1 svg1.4.5 template-string-converter0.4.7 git-graph1.29.0 vscode-language-pack-de1.54.1 vscode-dotnet-runtime1.0.0 vscode-edge-devtools1.1.3 python2021.2. jupyter2021.3. remote-containers0.163.0 remote-ssh0.64.0 remote-ssh-edit0.64.0 azure-account0.9.6 cpptools1.2.2 hexeditor1.4.0 vscode-github-issue-notebooks0.0.68 vscode-markdown-notebook0.0.14 debugger-for-chrome4.12.12 debugger-for-edge1.0.15 shader-toy0.10.15 </details<!-- generated by issue reporter --
I believe that webviews in diff editors are being leaked at the moment. For normal notebooks, I see the webview disposed of in the method: However I don't see the same in notebookTextDiffEditor
Hm, now I'm just more confused. It seems the webviews are not disposed of when the diff editor is closed (and is not fired on the either). However they are disposed of when another notebook diff editor is opened The root cause of this issue is that the webview is no longer in the dom but it also isn't disposed. We then try posting a message to it which causes an exception. Here's the call stack that triggers this error: !
I started to see leaks of recently, which is likely a regression, and probably in the logic.

Discussion:
private _eventDispatcher: NotebookDiffEditorEventDispatcher | undefined; protected _scopeContextKeyService!: IContextKeyService; private _model: INotebookDiffEditorModel | null = null; <del> private _modifiedResourceDisposableStore = new DisposableStore(); </del> <ins> private readonly _modifiedResourceDisposableStore = this._register(new DisposableStore()); </ins> private _outputRenderer: OutputRenderer; get textModel() {

protected _onDidDynamicOutputRendered = new Emitter<{ cell: IGenericCellViewModel, output: ICellOutputViewModel }>(); onDidDynamicOutputRendered = this._onDidDynamicOutputRendered.event; <del> private _localStore: DisposableStore = this._register(new DisposableStore()); </del> <ins> private readonly _localStore = this._register(new DisposableStore()); </ins> private _isDisposed: boolean = false;

this._fontInfo = BareFontInfo.createFromRawSettings(editorOptions, getZoomLevel(), getPixelRatio()); this._revealFirst = true; <del> this._register(this._modifiedResourceDisposableStore); </del> this._outputRenderer = new OutputRenderer(this, this.instantiationService); }

this._revealFirst = true; <ins> this._modifiedResourceDisposableStore.clear(); </ins> this._modifiedResourceDisposableStore.add(Event.any(this._model.original.notebook.onDidChangeContent, this._model.modified.notebook.onDidChangeContent)(e => { if (this._model !== null) { this.updateLayout();

})); await this._createOriginalWebview(generateUuid(), this._model.original.resource); <ins> if (this._originalWebview) { this._modifiedResourceDisposableStore.add(this._originalWebview); } </ins> await this._createModifiedWebview(generateUuid(), this._model.modified.resource); <ins> if (this._modifiedWebview) { this._modifiedResourceDisposableStore.add(this._modifiedWebview); } </ins> await this.updateLayout(); }

}; private async _createModifiedWebview(id: string, resource: URI): Promise<void> { <ins> if (this._modifiedWebview) { this._modifiedWebview.dispose(); } </ins> this._modifiedWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, this.webviewOptions) as BackLayerWebView<IDiffCellInfo>; // attach the webview container to the DOM tree first this._list.rowsContainer.insertAdjacentElement('afterbegin', this._modifiedWebview.element);

} private async _createOriginalWebview(id: string, resource: URI): Promise<void> { <ins> if (this._originalWebview) { this._originalWebview.dispose(); } </ins> this._originalWebview = this.instantiationService.createInstance(BackLayerWebView, this, id, resource, this.webviewOptions) as BackLayerWebView<IDiffCellInfo>; // attach the webview container to the DOM tree first this._list.rowsContainer.insertAdjacentElement('afterbegin', this._originalWebview.element);