From 6c5f85a25137f10272dcbc102b2adebb57753c20 Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Tue, 7 Jan 2025 13:29:11 -0600 Subject: [PATCH 1/2] Fixed bug with new panels not always showing initial content (DH-18347) --- src/controllers/PanelController.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/controllers/PanelController.ts b/src/controllers/PanelController.ts index 3a2839c7..145e9f1c 100644 --- a/src/controllers/PanelController.ts +++ b/src/controllers/PanelController.ts @@ -122,11 +122,17 @@ export class PanelController extends ControllerBase { await waitFor(0); let lastPanel: vscode.WebviewPanel | null = null; - let lastFirstTimeActiveSubscription: vscode.Disposable | null = null; + let lastPanelIsNew = false; + let lastCreatedPanelFirstTimeActiveSubscription: vscode.Disposable | null = + null; for (const variable of variables) { const { id, title } = variable; - if (!this._panelService.hasPanel(serverUrl, id)) { + if (this._panelService.hasPanel(serverUrl, id)) { + lastPanelIsNew = false; + } else { + lastPanelIsNew = true; + const panel = vscode.window.createWebviewPanel( 'dhPanel', // Identifies the type of the webview. Used internally title, @@ -147,7 +153,8 @@ export class PanelController extends ControllerBase { } } ); - lastFirstTimeActiveSubscription = onFirstTimeActiveSubscription; + lastCreatedPanelFirstTimeActiveSubscription = + onFirstTimeActiveSubscription; const onDidReceiveMessageSubscription = panel.webview.onDidReceiveMessage(({ data }) => { @@ -170,11 +177,14 @@ export class PanelController extends ControllerBase { lastPanel = panel; } - // Panels get created in an active state, so the last panel won't necessarily - // change from inactive to active. Remove the firstTimeActiveSubscription - // and refresh explicitly. - lastFirstTimeActiveSubscription?.dispose(); - this._onRefreshPanelsContent(serverUrl, variables.slice(-1)); + // Panels get created in an active state. If the last panel was newly created, + // it will already be active and won't call the `onDidChangeViewState` + // handler on the initial load. In such cases, remove the + // firstTimeActiveSubscription and refresh the panel explicitly. + if (lastPanelIsNew && lastCreatedPanelFirstTimeActiveSubscription) { + lastCreatedPanelFirstTimeActiveSubscription.dispose(); + this._onRefreshPanelsContent(serverUrl, variables.slice(-1)); + } lastPanel?.reveal(); }; From 8888c3a74cfbe28fd5f6612de3247f0035c945c7 Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Tue, 7 Jan 2025 13:50:21 -0600 Subject: [PATCH 2/2] Comments (DH-18347) --- src/controllers/PanelController.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/controllers/PanelController.ts b/src/controllers/PanelController.ts index 145e9f1c..1f94cefe 100644 --- a/src/controllers/PanelController.ts +++ b/src/controllers/PanelController.ts @@ -177,10 +177,19 @@ export class PanelController extends ControllerBase { lastPanel = panel; } - // Panels get created in an active state. If the last panel was newly created, - // it will already be active and won't call the `onDidChangeViewState` - // handler on the initial load. In such cases, remove the - // firstTimeActiveSubscription and refresh the panel explicitly. + // Panels get refreshed as follows: + // 1. Existing panels - don't get updated here. These get refreshed by a + // `subscribeToFieldUpdates` handler in DhcService which issues a + // `REFRESH_VARIABLE_PANELS_CMD` command for variables matching existing + // panels. + // 2. Newly created panels that are not the initially active panel (aka. any + // new panel that is not the last panel in the list) - these get refreshed + // the first time the panel becomes active via a one-time + // `onDidChangeViewState` handler. + // 3. Newly created panel that is the initially active panel - this one won't + // call the `onDidChangeViewState` handler since it is initialized as + // active. For this case, we dispose the one-time `onDidChangeViewState` + // subscription and refresh the panel explicitly. if (lastPanelIsNew && lastCreatedPanelFirstTimeActiveSubscription) { lastCreatedPanelFirstTimeActiveSubscription.dispose(); this._onRefreshPanelsContent(serverUrl, variables.slice(-1));