Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notebook: fixed small race condition for outputs #14789

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 webiviewWidgetInitialized = 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.webiviewWidgetInitialized.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.webiviewWidgetInitialized.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
Loading