Skip to content

Commit cd6cddb

Browse files
jonah-idenmsujew
andauthored
Notebook: fixed small race condition for outputs (eclipse-theia#14789)
* fixed small race condition if rendering happens before webviewwidget is instanciated --------- Signed-off-by: Jonah Iden <[email protected]> Co-authored-by: Mark Sujew <[email protected]>
1 parent d9a6525 commit cd6cddb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/notebook/src/browser/renderers/cell-output-webview.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,5 @@ export interface CellOutputWebview extends Disposable {
4545
onDidRenderOutput: Event<OutputRenderEvent>
4646

4747
requestOutputPresentationUpdate(cellHandle: number, output: NotebookCellOutputModel): void;
48-
49-
attachWebview(): void;
5048
isAttached(): boolean
5149
}

packages/plugin-ext/src/main/browser/notebooks/renderers/cell-output-webview.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { NotebookOptionsService, NotebookOutputOptions } from '@theia/notebook/l
4242
import { NotebookCellModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-model';
4343
import { CellOutput, NotebookCellsChangeType } from '@theia/notebook/lib/common';
4444
import { NotebookCellOutputModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-output-model';
45+
import { Deferred } from '@theia/core/lib/common/promise-util';
4546

4647
export const AdditionalNotebookCellOutputCss = Symbol('AdditionalNotebookCellOutputCss');
4748

@@ -242,6 +243,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
242243
protected element?: HTMLDivElement; // React.createRef<HTMLDivElement>();
243244

244245
protected webviewWidget: WebviewWidget;
246+
protected webviewWidgetInitialized = new Deferred();
245247

246248
protected toDispose = new DisposableCollection();
247249

@@ -257,6 +259,9 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
257259
}));
258260

259261
this.webviewWidget = await this.widgetManager.getOrCreateWidget(WebviewWidget.FACTORY_ID, { id: this.id });
262+
263+
this.webviewWidgetInitialized.resolve();
264+
260265
// this.webviewWidget.parent = this.editor ?? null;
261266
this.webviewWidget.setContentOptions({
262267
allowScripts: true,
@@ -331,15 +336,16 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
331336
}
332337

333338
render(): React.JSX.Element {
334-
return <div className='theia-notebook-cell-output-webview' ref={element => {
339+
return <div className='theia-notebook-cell-output-webview' ref={async element => {
335340
if (element) {
336341
this.element = element;
342+
await this.webviewWidgetInitialized.promise;
337343
this.attachWebview();
338344
}
339345
}}></div>;
340346
}
341347

342-
attachWebview(): void {
348+
protected attachWebview(): void {
343349
if (this.element) {
344350
this.webviewWidget.processMessage(new Message('before-attach'));
345351
this.element.appendChild(this.webviewWidget.node);

0 commit comments

Comments
 (0)