Skip to content

"Webview is disposed" error notification on switching to a branch #2828

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

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions src/common/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ export class WebviewViewBase extends WebviewBase {
public readonly viewType: string;
protected _view?: vscode.WebviewView;

constructor(
protected readonly _extensionUri: vscode.Uri) {
super();
}

protected resolveWebviewView(
webviewView: vscode.WebviewView,
_context: vscode.WebviewViewResolveContext,
_token: vscode.CancellationToken) {
this._view = webviewView;
this._webview = webviewView.webview;
super.initialize();
webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,

localResourceRoots: [this._extensionUri],
};
this._disposables.push(this._view.onDidDispose(() => {
this._webview = undefined;
this._view = undefined;
}));
}

public show() {
if (this._view) {
this._view.show();
Expand Down
16 changes: 3 additions & 13 deletions src/github/activityBarViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
private _existingReviewers: ReviewState[] = [];

constructor(
private readonly _extensionUri: vscode.Uri,
extensionUri: vscode.Uri,
private readonly _folderRepositoryManager: FolderRepositoryManager,
private _item: PullRequestModel,
) {
super();
super(extensionUri);

this.registerFolderRepositoryListener();

Expand Down Expand Up @@ -68,17 +68,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
_context: vscode.WebviewViewResolveContext,
_token: vscode.CancellationToken,
) {
this._view = webviewView;
this._webview = webviewView.webview;
super.initialize();

webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,

localResourceRoots: [this._extensionUri],
};

super.resolveWebviewView(webviewView, _context, _token);
webviewView.webview.html = this._getHtmlForWebview();

this.updatePullRequest(this._item);
Expand Down
15 changes: 3 additions & 12 deletions src/github/createPRViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
private _firstLoad: boolean = true;

constructor(
private readonly _extensionUri: vscode.Uri,
extensionUri: vscode.Uri,
private readonly _folderRepositoryManager: FolderRepositoryManager,
private readonly _pullRequestDefaults: PullRequestDefaults,
compareBranch: Branch,
) {
super();
super(extensionUri);

this._compareBranch = compareBranch;
}
Expand All @@ -60,16 +60,7 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
_context: vscode.WebviewViewResolveContext,
_token: vscode.CancellationToken,
) {
this._view = webviewView;
this._webview = webviewView.webview;
super.initialize();
webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,

localResourceRoots: [this._extensionUri],
};

super.resolveWebviewView(webviewView, _context, _token);
webviewView.webview.html = this._getHtmlForWebview();

if (this._firstLoad) {
Expand Down
5 changes: 3 additions & 2 deletions src/github/issueOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
const activeColumn = toTheSide
? vscode.ViewColumn.Beside
: vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
: vscode.ViewColumn.One;
? vscode.window.activeTextEditor.viewColumn
: vscode.ViewColumn.One;

// If we already have a panel, show it.
// Otherwise, create a new panel.
Expand Down Expand Up @@ -364,6 +364,7 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W

// Clean up our resources
this._panel.dispose();
this._webview = undefined;

while (this._disposables.length) {
const x = this._disposables.pop();
Expand Down