From 6c95ac7c790d033bc286e9201667329c6aa6c7c9 Mon Sep 17 00:00:00 2001 From: Koen Vlaswinkel Date: Thu, 6 Apr 2023 14:57:58 +0200 Subject: [PATCH] Fix error when closing MRVA webview during extension activation This fixes the "Webview is disposed" error which occurs when the user closes the variant analysis webview while the extension is still activating. We will now check whether the webview is disposed before restoring the view. --- .../variant-analysis-view-serializer.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/extensions/ql-vscode/src/variant-analysis/variant-analysis-view-serializer.ts b/extensions/ql-vscode/src/variant-analysis/variant-analysis-view-serializer.ts index 314a3e0ba..7ce93f372 100644 --- a/extensions/ql-vscode/src/variant-analysis/variant-analysis-view-serializer.ts +++ b/extensions/ql-vscode/src/variant-analysis/variant-analysis-view-serializer.ts @@ -37,6 +37,14 @@ export class VariantAnalysisViewSerializer implements WebviewPanelSerializer { return; } + // Between the time the webview is deserialized and the time the extension + // is fully activated, the user may close the webview. In this case, we + // should not attempt to restore the view. + let disposed = false; + const unregisterOnDidDispose = webviewPanel.onDidDispose(() => { + disposed = true; + }); + const variantAnalysisState: VariantAnalysisState = state as VariantAnalysisState; @@ -46,11 +54,16 @@ export class VariantAnalysisViewSerializer implements WebviewPanelSerializer { variantAnalysisState.variantAnalysisId, ); if (existingView) { + unregisterOnDidDispose.dispose(); await existingView.openView(); webviewPanel.dispose(); return; } + if (disposed) { + return; + } + const view = new VariantAnalysisView( this.ctx, this.app, @@ -58,6 +71,8 @@ export class VariantAnalysisViewSerializer implements WebviewPanelSerializer { manager, ); await view.restoreView(webviewPanel); + + unregisterOnDidDispose.dispose(); } private waitForExtensionFullyLoaded(): Promise<