File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -230,6 +230,17 @@ export class PullRequestCommentController extends CommentControllerBase implemen
230230 private async onDidChangeReviewThreads ( e : ReviewThreadChangeEvent ) : Promise < void > {
231231 for ( const thread of e . added ) {
232232 const fileName = thread . path ;
233+ const key = this . getCommentThreadCacheKey ( thread . path , thread . diffSide === DiffSide . LEFT ) ;
234+
235+ // Defensive: if a comment thread for this review thread id already exists in the cache
236+ // (e.g. because addThreadsForEditors already created it from the cache before this event was
237+ // processed), update it in place instead of creating a duplicate VS Code comment thread.
238+ const existing = this . _commentThreadCache [ key ] ?. find ( t => t . gitHubThreadId === thread . id ) ;
239+ if ( existing ) {
240+ updateThread ( this . _context , existing , thread , this . _githubRepositories ) ;
241+ continue ;
242+ }
243+
233244 const index = this . _pendingCommentThreadAdds . findIndex ( t => {
234245 const samePath = this . _folderRepoManager . gitRelativeRootPath ( t . uri . path ) === thread . path ;
235246 const sameLine = ( t . range === undefined && thread . subjectType === SubjectType . FILE ) || ( t . range && t . range . end . line + 1 === thread . endLine ) ;
@@ -270,9 +281,8 @@ export class PullRequestCommentController extends CommentControllerBase implemen
270281 }
271282
272283 if ( ! newThread ) {
273- return ;
284+ continue ;
274285 }
275- const key = this . getCommentThreadCacheKey ( thread . path , thread . diffSide === DiffSide . LEFT ) ;
276286 if ( this . _commentThreadCache [ key ] ) {
277287 this . _commentThreadCache [ key ] . push ( newThread ) ;
278288 } else {
Original file line number Diff line number Diff line change @@ -280,6 +280,17 @@ export class ReviewCommentController extends CommentControllerBase implements Co
280280 for ( const thread of e . added ) {
281281 const { path } = thread ;
282282
283+ // Defensive: if a comment thread for this review thread id already exists in any of the
284+ // thread maps (e.g. because doInitializeCommentThreads already created it from the cache
285+ // before this event was processed), update it in place instead of creating a duplicate
286+ // VS Code comment thread.
287+ const existingMatch = this . _findMatchingThread ( thread ) ;
288+ if ( existingMatch . index > - 1 ) {
289+ const matchingThread = existingMatch . threadMap [ thread . path ] [ existingMatch . index ] ;
290+ updateThread ( this . _context , matchingThread , thread , githubRepositories ) ;
291+ continue ;
292+ }
293+
283294 const index = await arrayFindIndexAsync ( this . _pendingCommentThreadAdds , async t => {
284295 const fileName = this . _folderRepoManager . gitRelativeRootPath ( t . uri . path ) ;
285296 if ( fileName !== thread . path ) {
You can’t perform that action at this time.
0 commit comments