From 48371146db730e3aa09f4de0fc1c34c9a29fb6a4 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Thu, 27 Jul 2023 20:54:13 +0000 Subject: [PATCH] improve handling of initial currentWidget --- packages/labextension/src/tracker.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/labextension/src/tracker.ts b/packages/labextension/src/tracker.ts index 89c9f92..c96db79 100644 --- a/packages/labextension/src/tracker.ts +++ b/packages/labextension/src/tracker.ts @@ -34,8 +34,15 @@ export class KernelWidgetTracker { }); } } - this._currentWidget = - notebookTracker.currentWidget ?? consoleTracker?.currentWidget ?? null; + // handle an existing current widget in case the KernelWidgetTracker + // is created a bit later, or if there is already a Notebook widget available + // on page load like in Notebook 7. + if (labShell?.currentWidget && hasKernelSession(labShell?.currentWidget)) { + this._currentWidget = labShell.currentWidget; + } else { + this._currentWidget = + notebookTracker.currentWidget ?? consoleTracker?.currentWidget ?? null; + } } /**