Skip to content

Commit

Permalink
Make sure webview editor has not been disposed before claiming webview
Browse files Browse the repository at this point in the history
Fixes microsoft#115743

Also added an exception to make sure we don't call `show` on a disposed of webview editor overlay
  • Loading branch information
mjbvz committed Feb 12, 2021
1 parent 0568d26 commit 2e1166c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv
return !!this._webview.value?.isFocused;
}

private _isDisposed = false;

private readonly _onDidDispose = this._register(new Emitter<void>());
public onDidDispose = this._onDidDispose.event;

dispose() {
this._isDisposed = true;
this.container.remove();
this._onDidDispose.fire();
super.dispose();
Expand Down Expand Up @@ -138,6 +141,10 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv
}

private show() {
if (this._isDisposed) {
throw new Error('Webview overlay is disposed');
}

if (!this._webview.value) {
const webview = this._webviewService.createWebviewElement(this.id, this._options, this._contentOptions, this.extension);
this._webview.value = webview;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class WebviewEditor extends EditorPane {
private _element?: HTMLElement;
private _dimension?: DOM.Dimension;
private _visible = false;
private _isDisposed = false;

private readonly _webviewVisibleDisposables = this._register(new DisposableStore());
private readonly _onFocusWindowHandler = this._register(new MutableDisposable());
Expand Down Expand Up @@ -71,6 +72,8 @@ export class WebviewEditor extends EditorPane {
}

public dispose(): void {
this._isDisposed = true;

if (this._element) {
this._element.remove();
this._element = undefined;
Expand Down Expand Up @@ -133,7 +136,7 @@ export class WebviewEditor extends EditorPane {
await super.setInput(input, options, context, token);
await input.resolve();

if (token.isCancellationRequested) {
if (token.isCancellationRequested || this._isDisposed) {
return;
}

Expand Down

0 comments on commit 2e1166c

Please sign in to comment.