@@ -252,6 +252,7 @@ function PullRequestCodeTab({
252252 onAddToAgentSelection,
253253 onRefresh,
254254 refreshToken = 0 ,
255+ backgroundRefreshToken = 0 ,
255256 revealRequest = null ,
256257} : {
257258 scrollerRef : ( node : HTMLDivElement | null ) => void ;
@@ -266,6 +267,7 @@ function PullRequestCodeTab({
266267 onAddToAgentSelection ?: ( input : PullRequestAgentSelectionInput ) => void ;
267268 onRefresh : ( ) => void ;
268269 refreshToken ?: number ;
270+ backgroundRefreshToken ?: number ;
269271 revealRequest ?: { readonly path : string ; readonly nonce : number } | null ;
270272} ) {
271273 const { resolvedTheme } = useTheme ( ) ;
@@ -308,7 +310,7 @@ function PullRequestCodeTab({
308310
309311 const referenceKey = pullRequestReviewKey ( reference ) ;
310312 const commit = selectedCommitOid ;
311- const scopeKey = commit === null ? referenceKey : ` ${ referenceKey } @ ${ commit } ` ;
313+ const scopeKey = JSON . stringify ( [ environmentId , referenceKey , commit ] ) ;
312314 // The panel keeps this mounted across pull requests, so an open composer would otherwise
313315 // survive the switch and attach its comment to whichever one is on screen when it is sent.
314316 const [ stateScopeKey , setStateScopeKey ] = useState ( scopeKey ) ;
@@ -432,6 +434,15 @@ function PullRequestCodeTab({
432434 refreshFirstDiffPage ( ) ;
433435 refreshFilesViewed ( ) ;
434436 } , [ refreshToken , scopeKey , refreshFirstDiffPage , refreshFilesViewed ] ) ;
437+ const appliedBackgroundRefreshToken = useRef ( backgroundRefreshToken ) ;
438+ useEffect ( ( ) => {
439+ if ( appliedBackgroundRefreshToken . current === backgroundRefreshToken ) return ;
440+ appliedBackgroundRefreshToken . current = backgroundRefreshToken ;
441+ // Keeping slices mounted preserves scroll; the page merge invalidates changed pages.
442+ setSliceState ( ( previous ) => ( { ...previous , cursor : null } ) ) ;
443+ refreshFirstDiffPage ( ) ;
444+ refreshFilesViewed ( ) ;
445+ } , [ backgroundRefreshToken , refreshFirstDiffPage , refreshFilesViewed ] ) ;
435446
436447 // The sentinel is held as state rather than a ref because the viewer mounts its own footer:
437448 // an effect reading a ref could run before that node exists and would never arm the observer.
0 commit comments