From 6ab73b0a5e10447dffd4455dc7882da2c1ac68f7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Nov 2026 09:38:55 +0000 Subject: [PATCH 1/2] Initial plan From ef2b49e5f65fbd2a9996ec7b5113d484c3b3023a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Nov 2026 09:48:31 +0000 Subject: [PATCH 2/2] Don't show a refresh error when the PR description closes mid-refresh Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> --- src/github/pullRequestOverview.ts | 15 ++++-- src/test/github/pullRequestOverview.test.ts | 55 +++++++++++++++++++-- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/github/pullRequestOverview.ts b/src/github/pullRequestOverview.ts index 8027a67f48..8fe71c1eea 100644 --- a/src/github/pullRequestOverview.ts +++ b/src/github/pullRequestOverview.ts @@ -543,7 +543,8 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel { - while (this._pendingUpdate) { + // An update that was queued before the panel was closed cannot be shown. + while (this._pendingUpdate && !this.isDisposed) { const pullRequestModel = this._pendingUpdate; this._pendingUpdate = undefined; await this.updateItemNow(pullRequestModel); @@ -959,12 +960,16 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel { - if (!this._panel.visible || this._refreshing) { + if (this.isDisposed || !this._panel.visible || this._refreshing) { return; } this._refreshing = true; try { const pullRequest = await this.resolveModel(this._identity); + // The panel can be closed while the pull request is resolved, such as when merging it checks out the default branch. + if (this.isDisposed) { + return; + } if (!pullRequest) { throw new Error( `Failed to resolve Pull Request #${this._identity.number} in ${this._identity.owner}/${this._identity.repo}`, @@ -972,7 +977,11 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel void; + resolvePullRequest.resetHistory(); + resolvePullRequest.callsFake(() => new Promise(resolve => reloadPullRequest = resolve)); + + // Merging the pull request refreshes the panel. + model.update({ ...model.item, state: 'MERGED', merged: true }); + sinon.assert.calledOnce(resolvePullRequest); + // Checking out the default branch after the merge closes the panel before the refresh finishes. + webviewPanel.dispose(); + reloadPullRequest(model); + await new Promise(resolve => setImmediate(resolve)); + + sinon.assert.notCalled(showError); + }); + + it('does nothing when the panel is refreshed after it is closed', async function () { + const { panel, resolvePullRequest, showError, webviewPanel } = await createPanel(); + resolvePullRequest.resetHistory(); + webviewPanel.dispose(); + + await panel.refreshPanel(); + + sinon.assert.notCalled(resolvePullRequest); + sinon.assert.notCalled(showError); + }); + + it('does not apply an update that was queued before the panel closed', async function () { + const { panel, model, defaultBranch, showError, webviewPanel } = await createPanel(); + let finishUpdate!: (defaultBranch: string) => void; + defaultBranch.returns(new Promise(resolve => finishUpdate = resolve)); + defaultBranch.resetHistory(); + const refreshing = panel.refreshPanel(); + await new Promise(resolve => setImmediate(resolve)); + sinon.assert.calledOnce(defaultBranch); + + const identity = { owner: remote.owner, repo: remote.repositoryName, number: model.number }; + const reopening = PullRequestOverviewPanel.createOrShow(telemetry, EXTENSION_URI, pullRequestManager, identity, model, false, true, webviewPanel); + webviewPanel.dispose(); + finishUpdate('main'); + await Promise.all([refreshing, reopening]); + + sinon.assert.calledOnce(defaultBranch); + sinon.assert.notCalled(showError); + }); + }); + describe('mergeStack', function () { const stack: PullRequestStack = { position: 2, @@ -1532,7 +1581,7 @@ describe('PullRequestOverview', function () { mergeMethodsAvailability: { merge: true, squash: true, rebase: true }, viewerCanAutoMerge: false, }); - sinon.stub(pullRequestManager, 'getPullRequestRepositoryDefaultBranch').resolves('main'); + const defaultBranch = sinon.stub(pullRequestManager, 'getPullRequestRepositoryDefaultBranch').resolves('main'); const currentUser = sinon.stub(pullRequestManager, 'getCurrentUser').callsFake(async () => { const model = models.values().next().value; assert(model); @@ -1549,7 +1598,7 @@ describe('PullRequestOverview', function () { const showError = sinon.stub(vscode.window, 'showErrorMessage').resolves(undefined); const stackablePullRequests = sinon.stub(repo, 'getStackablePullRequests').resolves({}); const query = sinon.spy(repo, 'query'); - return { models, access, currentUser, branch, queueMethod, resolvePullRequest, externalUri, showError, stackablePullRequests, query }; + return { models, access, defaultBranch, currentUser, branch, queueMethod, resolvePullRequest, externalUri, showError, stackablePullRequests, query }; } /** A pull request whose branches are both in the test repository, so it can be stacked. */ @@ -1625,7 +1674,7 @@ describe('PullRequestOverview', function () { { position: 2, number: 1000, title: 'Second', url: '', head: 'D2', state: GithubItemStateEnum.Open, isDraft: false, mergeable: PullRequestMergeability.Mergeable }, ], }); - return { ...services, panel, model, stackQuery, webviewPostMessage, received, onDidPost: posted.event }; + return { ...services, panel, model, stackQuery, webviewPanel, webviewPostMessage, received, onDidPost: posted.event }; } describe('stack panel fixture', function () {