From f98ef1c1db553d919bb12e322be7dc7c8e14695b Mon Sep 17 00:00:00 2001 From: Vatsal Uppal Date: Sun, 20 Aug 2023 21:26:55 +0530 Subject: [PATCH 1/2] Fixed webviews fail to restore on application start --- .../src/hosted/browser/hosted-plugin.ts | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts index df424168e1531..921d415060851 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts +++ b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts @@ -304,8 +304,6 @@ export class HostedPluginSupport { await this.startPlugins(contributionsByHost, toDisconnect); this.deferredDidStart.resolve(); - - this.restoreWebviews(); } /** @@ -757,7 +755,7 @@ export class HostedPluginSupport { return `${plugins} plugin${plugins === 1 ? '' : 's'}`; } - protected readonly webviewsToRestore = new Set(); + protected readonly webviewsToRestore = new Map(); protected readonly webviewRevivers = new Map Promise>(); registerWebviewReviver(viewType: string, reviver: (webview: WebviewWidget) => Promise): void { @@ -765,6 +763,10 @@ export class HostedPluginSupport { throw new Error(`Reviver for ${viewType} already registered`); } this.webviewRevivers.set(viewType, reviver); + + if (this.webviewsToRestore.has(viewType)) { + this.restoreWebview(this.webviewsToRestore.get(viewType) as WebviewWidget); + } } unregisterWebviewReviver(viewType: string): void { @@ -785,17 +787,10 @@ export class HostedPluginSupport { } protected preserveWebview(webview: WebviewWidget): void { - if (!this.webviewsToRestore.has(webview)) { - this.webviewsToRestore.add(webview); - webview.disposed.connect(() => this.webviewsToRestore.delete(webview)); - } - } - - protected restoreWebviews(): void { - for (const webview of this.webviewsToRestore) { - this.restoreWebview(webview); + if (!this.webviewsToRestore.has(webview.viewType)) { + this.webviewsToRestore.set(webview.viewType, webview); + webview.disposed.connect(() => this.webviewsToRestore.delete(webview.viewType)); } - this.webviewsToRestore.clear(); } protected async restoreWebview(webview: WebviewWidget): Promise { From af28e80751bc30746f8107b9d39ed95a3aeda270 Mon Sep 17 00:00:00 2001 From: Vatsal Uppal Date: Sun, 20 Aug 2023 23:12:15 +0530 Subject: [PATCH 2/2] Activate by event should be called with preserveWebview --- packages/plugin-ext/src/hosted/browser/hosted-plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts index 921d415060851..500d6f4b8d611 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts +++ b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts @@ -788,13 +788,13 @@ export class HostedPluginSupport { protected preserveWebview(webview: WebviewWidget): void { if (!this.webviewsToRestore.has(webview.viewType)) { + this.activateByEvent(`onWebviewPanel:${webview.viewType}`); this.webviewsToRestore.set(webview.viewType, webview); webview.disposed.connect(() => this.webviewsToRestore.delete(webview.viewType)); } } protected async restoreWebview(webview: WebviewWidget): Promise { - await this.activateByEvent(`onWebviewPanel:${webview.viewType}`); const restore = this.webviewRevivers.get(webview.viewType); if (restore) { try {