Skip to content

Commit

Permalink
Notebook: fixed small race condition for outputs (#14789)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
jonah-iden and msujew authored Jan 29, 2025
1 parent d9a6525 commit cd6cddb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,5 @@ export interface CellOutputWebview extends Disposable {
onDidRenderOutput: Event<OutputRenderEvent>

requestOutputPresentationUpdate(cellHandle: number, output: NotebookCellOutputModel): void;

attachWebview(): void;
isAttached(): boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');

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

protected webviewWidget: WebviewWidget;
protected webviewWidgetInitialized = new Deferred();

protected toDispose = new DisposableCollection();

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

this.webviewWidget = await this.widgetManager.getOrCreateWidget(WebviewWidget.FACTORY_ID, { id: this.id });

this.webviewWidgetInitialized.resolve();

// this.webviewWidget.parent = this.editor ?? null;
this.webviewWidget.setContentOptions({
allowScripts: true,
Expand Down Expand Up @@ -331,15 +336,16 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
}

render(): React.JSX.Element {
return <div className='theia-notebook-cell-output-webview' ref={element => {
return <div className='theia-notebook-cell-output-webview' ref={async element => {
if (element) {
this.element = element;
await this.webviewWidgetInitialized.promise;
this.attachWebview();
}
}}></div>;
}

attachWebview(): void {
protected attachWebview(): void {
if (this.element) {
this.webviewWidget.processMessage(new Message('before-attach'));
this.element.appendChild(this.webviewWidget.node);
Expand Down

0 comments on commit cd6cddb

Please sign in to comment.