From 736f42912b18a5475f125e7aeadca92aa39e7e69 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Wed, 25 Oct 2023 12:13:47 +0100 Subject: [PATCH] Initial fix for node attachment issue with windowed notebook --- src/ExecuteTimeWidget.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ExecuteTimeWidget.ts b/src/ExecuteTimeWidget.ts index d17d254..3bffa46 100644 --- a/src/ExecuteTimeWidget.ts +++ b/src/ExecuteTimeWidget.ts @@ -160,6 +160,20 @@ export default class ExecuteTimeWidget extends Widget { await cell.ready; const executionMetadata = cell.model.getMetadata('execution') as JSONObject; if (executionMetadata && JSONExt.isObject(executionMetadata)) { + // Wait until the cell is in viewport before querying for the node, + // as otherwise it would not be found as contents are detached from DOM. + if (!cell.inViewport) { + // TODO: cancel the update if another update was scheduled since. + await new Promise((resolved) => { + const handler = (_emitter: Cell, attached: boolean) => { + if (attached) { + resolved(); + cell.inViewportChanged.disconnect(handler); + } + }; + cell.inViewportChanged.connect(handler); + }); + } let executionTimeNode: HTMLDivElement = cell.node.querySelector( `.${EXECUTE_TIME_CLASS}` );