From 0d9cb09dc4791fd87fccede76dd22549d5426e4f Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Wed, 29 Jan 2025 10:49:38 +0100 Subject: [PATCH 1/2] fixed small race condition if rendering happens before webviewwidget is instanciated Signed-off-by: Jonah Iden --- .../src/browser/renderers/cell-output-webview.ts | 2 -- .../notebooks/renderers/cell-output-webview.tsx | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/notebook/src/browser/renderers/cell-output-webview.ts b/packages/notebook/src/browser/renderers/cell-output-webview.ts index e838f143df911..acd5a0fbbe1ab 100644 --- a/packages/notebook/src/browser/renderers/cell-output-webview.ts +++ b/packages/notebook/src/browser/renderers/cell-output-webview.ts @@ -45,7 +45,5 @@ export interface CellOutputWebview extends Disposable { onDidRenderOutput: Event requestOutputPresentationUpdate(cellHandle: number, output: NotebookCellOutputModel): void; - - attachWebview(): void; isAttached(): boolean } diff --git a/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx b/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx index e55d7c6f27802..24bbd23602d43 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx +++ b/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx @@ -42,6 +42,7 @@ import { NotebookOptionsService, NotebookOutputOptions } from '@theia/notebook/l import { NotebookCellModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-model'; import { CellOutput, NotebookCellsChangeType } from '@theia/notebook/lib/common'; import { NotebookCellOutputModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-output-model'; +import { Deferred } from '@theia/core/lib/common/promise-util'; export const AdditionalNotebookCellOutputCss = Symbol('AdditionalNotebookCellOutputCss'); @@ -242,6 +243,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { protected element?: HTMLDivElement; // React.createRef(); protected webviewWidget: WebviewWidget; + protected webiviewWidgetInitialized = new Deferred(); protected toDispose = new DisposableCollection(); @@ -257,6 +259,9 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { })); this.webviewWidget = await this.widgetManager.getOrCreateWidget(WebviewWidget.FACTORY_ID, { id: this.id }); + + this.webiviewWidgetInitialized.resolve(); + // this.webviewWidget.parent = this.editor ?? null; this.webviewWidget.setContentOptions({ allowScripts: true, @@ -331,15 +336,16 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { } render(): React.JSX.Element { - return
{ + return
{ if (element) { this.element = element; + await this.webiviewWidgetInitialized.promise; this.attachWebview(); } }}>
; } - attachWebview(): void { + protected attachWebview(): void { if (this.element) { this.webviewWidget.processMessage(new Message('before-attach')); this.element.appendChild(this.webviewWidget.node); From 841139ca705e222e4cfeac6eaefd0f28ad242e1c Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Wed, 29 Jan 2025 12:28:16 +0100 Subject: [PATCH 2/2] typo fix Co-authored-by: Mark Sujew Signed-off-by: Jonah Iden --- .../browser/notebooks/renderers/cell-output-webview.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx b/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx index 24bbd23602d43..938a46b36b12b 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx +++ b/packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx @@ -243,7 +243,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { protected element?: HTMLDivElement; // React.createRef(); protected webviewWidget: WebviewWidget; - protected webiviewWidgetInitialized = new Deferred(); + protected webviewWidgetInitialized = new Deferred(); protected toDispose = new DisposableCollection(); @@ -260,7 +260,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { this.webviewWidget = await this.widgetManager.getOrCreateWidget(WebviewWidget.FACTORY_ID, { id: this.id }); - this.webiviewWidgetInitialized.resolve(); + this.webviewWidgetInitialized.resolve(); // this.webviewWidget.parent = this.editor ?? null; this.webviewWidget.setContentOptions({ @@ -339,7 +339,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable { return
{ if (element) { this.element = element; - await this.webiviewWidgetInitialized.promise; + await this.webviewWidgetInitialized.promise; this.attachWebview(); } }}>
;