@@ -15,6 +15,7 @@ import { MergeArguments, PullRequest, ReviewType } from './views';
1515import { IComment } from '../common/comment' ;
1616import { emojify , ensureEmojis } from '../common/emoji' ;
1717import { disposeAll } from '../common/lifecycle' ;
18+ import Logger from '../common/logger' ;
1819import { CHECKOUT_DEFAULT_BRANCH , CHECKOUT_PULL_REQUEST_BASE_BRANCH , DELETE_BRANCH_AFTER_MERGE , POST_DONE , PR_SETTINGS_NAMESPACE } from '../common/settingKeys' ;
1920import { ReviewEvent } from '../common/timelineEvent' ;
2021import { formatError } from '../common/utils' ;
@@ -25,7 +26,7 @@ import { ReviewManager } from '../view/reviewManager';
2526export class PullRequestViewProvider extends WebviewViewBase implements vscode . WebviewViewProvider {
2627 public override readonly viewType = 'github:activePullRequest' ;
2728 private _existingReviewers : ReviewState [ ] = [ ] ;
28- private _isUpdating : boolean = false ;
29+ private _updatingPromise : Promise < unknown > | undefined ;
2930
3031 constructor (
3132 extensionUri : vscode . Uri ,
@@ -151,7 +152,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
151152 }
152153 this . _prDisposables = [ ] ;
153154 this . _prDisposables . push ( pullRequestModel . onDidChange ( e => {
154- if ( ( e . state || e . comments || e . reviewers ) && ! this . _isUpdating ) {
155+ if ( ( e . state || e . comments || e . reviewers ) && ! this . _updatingPromise ) {
155156 this . updatePullRequest ( pullRequestModel ) ;
156157 }
157158 } ) ) ;
@@ -160,10 +161,16 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
160161
161162 private _updatePendingVisibility : vscode . Disposable | undefined = undefined ;
162163 public async updatePullRequest ( pullRequestModel : PullRequestModel ) : Promise < void > {
163- if ( this . _isUpdating ) {
164- throw new Error ( 'Already updating pull request view' ) ;
164+ const isSamePullRequest = pullRequestModel . equals ( this . _item ) ;
165+ if ( this . _updatingPromise && isSamePullRequest ) {
166+ Logger . error ( 'Already updating pull request view' , PullRequestViewProvider . name ) ;
167+ return ;
168+ } else if ( this . _updatingPromise && ! isSamePullRequest ) {
169+ this . _item = pullRequestModel ;
170+ await this . _updatingPromise ;
171+ } else {
172+ this . _item = pullRequestModel ;
165173 }
166- this . _isUpdating = true ;
167174
168175 try {
169176 if ( this . _view && ! this . _view . visible ) {
@@ -178,7 +185,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
178185 this . registerPrSpecificListeners ( pullRequestModel ) ;
179186 }
180187 this . _item = pullRequestModel ;
181- const [ pullRequest , repositoryAccess , timelineEvents , requestedReviewers , branchInfo , defaultBranch , currentUser , viewerCanEdit , hasReviewDraft , coAuthors ] = await Promise . all ( [
188+ const updatingPromise = Promise . all ( [
182189 this . _folderRepositoryManager . resolvePullRequest (
183190 pullRequestModel . remote . owner ,
184191 pullRequestModel . remote . repositoryName ,
@@ -195,13 +202,19 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
195202 pullRequestModel . getCoAuthors ( ) ,
196203 ensureEmojis ( this . _folderRepositoryManager . context )
197204 ] ) ;
205+ this . _updatingPromise = updatingPromise ;
206+ const [ pullRequest , repositoryAccess , timelineEvents , requestedReviewers , branchInfo , defaultBranch , currentUser , viewerCanEdit , hasReviewDraft , coAuthors ] = await updatingPromise ;
198207
199208 if ( ! pullRequest ) {
200209 throw new Error (
201210 `Fail to resolve Pull Request #${ pullRequestModel . number } in ${ pullRequestModel . remote . owner } /${ pullRequestModel . remote . repositoryName } ` ,
202211 ) ;
203212 }
204213
214+ if ( ! this . _item . equals ( pullRequestModel ) ) {
215+ return ;
216+ }
217+
205218 this . _item = pullRequest ;
206219 if ( ! this . _view ) {
207220 // If the there is no PR webview, then there is nothing else to update.
@@ -292,8 +305,6 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
292305
293306 } catch ( e ) {
294307 vscode . window . showErrorMessage ( `Error updating active pull request view: ${ formatError ( e ) } ` ) ;
295- } finally {
296- this . _isUpdating = false ;
297308 }
298309 }
299310
0 commit comments