Skip to content

Commit 4c604a1

Browse files
authored
"Webview is disposed" error notification on switching to a branch (microsoft#2828)
Fixes microsoft#2444
1 parent 7af0261 commit 4c604a1

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

src/common/webview.ts

+24
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ export class WebviewViewBase extends WebviewBase {
101101
public readonly viewType: string;
102102
protected _view?: vscode.WebviewView;
103103

104+
constructor(
105+
protected readonly _extensionUri: vscode.Uri) {
106+
super();
107+
}
108+
109+
protected resolveWebviewView(
110+
webviewView: vscode.WebviewView,
111+
_context: vscode.WebviewViewResolveContext,
112+
_token: vscode.CancellationToken) {
113+
this._view = webviewView;
114+
this._webview = webviewView.webview;
115+
super.initialize();
116+
webviewView.webview.options = {
117+
// Allow scripts in the webview
118+
enableScripts: true,
119+
120+
localResourceRoots: [this._extensionUri],
121+
};
122+
this._disposables.push(this._view.onDidDispose(() => {
123+
this._webview = undefined;
124+
this._view = undefined;
125+
}));
126+
}
127+
104128
public show() {
105129
if (this._view) {
106130
this._view.show();

src/github/activityBarViewProvider.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
2020
private _existingReviewers: ReviewState[] = [];
2121

2222
constructor(
23-
private readonly _extensionUri: vscode.Uri,
23+
extensionUri: vscode.Uri,
2424
private readonly _folderRepositoryManager: FolderRepositoryManager,
2525
private _item: PullRequestModel,
2626
) {
27-
super();
27+
super(extensionUri);
2828

2929
this.registerFolderRepositoryListener();
3030

@@ -68,17 +68,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
6868
_context: vscode.WebviewViewResolveContext,
6969
_token: vscode.CancellationToken,
7070
) {
71-
this._view = webviewView;
72-
this._webview = webviewView.webview;
73-
super.initialize();
74-
75-
webviewView.webview.options = {
76-
// Allow scripts in the webview
77-
enableScripts: true,
78-
79-
localResourceRoots: [this._extensionUri],
80-
};
81-
71+
super.resolveWebviewView(webviewView, _context, _token);
8272
webviewView.webview.html = this._getHtmlForWebview();
8373

8474
this.updatePullRequest(this._item);

src/github/createPRViewProvider.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
4545
private _firstLoad: boolean = true;
4646

4747
constructor(
48-
private readonly _extensionUri: vscode.Uri,
48+
extensionUri: vscode.Uri,
4949
private readonly _folderRepositoryManager: FolderRepositoryManager,
5050
private readonly _pullRequestDefaults: PullRequestDefaults,
5151
compareBranch: Branch,
5252
) {
53-
super();
53+
super(extensionUri);
5454

5555
this._compareBranch = compareBranch;
5656
}
@@ -60,16 +60,7 @@ export class CreatePullRequestViewProvider extends WebviewViewBase implements vs
6060
_context: vscode.WebviewViewResolveContext,
6161
_token: vscode.CancellationToken,
6262
) {
63-
this._view = webviewView;
64-
this._webview = webviewView.webview;
65-
super.initialize();
66-
webviewView.webview.options = {
67-
// Allow scripts in the webview
68-
enableScripts: true,
69-
70-
localResourceRoots: [this._extensionUri],
71-
};
72-
63+
super.resolveWebviewView(webviewView, _context, _token);
7364
webviewView.webview.html = this._getHtmlForWebview();
7465

7566
if (this._firstLoad) {

src/github/issueOverview.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
4040
const activeColumn = toTheSide
4141
? vscode.ViewColumn.Beside
4242
: vscode.window.activeTextEditor
43-
? vscode.window.activeTextEditor.viewColumn
44-
: vscode.ViewColumn.One;
43+
? vscode.window.activeTextEditor.viewColumn
44+
: vscode.ViewColumn.One;
4545

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

365365
// Clean up our resources
366366
this._panel.dispose();
367+
this._webview = undefined;
367368

368369
while (this._disposables.length) {
369370
const x = this._disposables.pop();

0 commit comments

Comments
 (0)