Skip to content

Commit 073a20a

Browse files
sameerr03claudejuliusmarminge
authored
fix(web): PR code view keeps its scroll when a turn finishes (pingdotgg#13835)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 6cd6372 commit 073a20a

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestCodeTab.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ export function PullRequestDetailPanel({
831831
nativeStackQuery.refresh();
832832
};
833833
const [refreshToken, setRefreshToken] = useState(0);
834-
const codeRefreshToken = refreshToken + (turnRefresh ?? 0);
835834
const [activityRevision, setActivityRevision] = useState<{
836835
readonly key: string;
837836
readonly updatedAt: string;
@@ -2878,7 +2877,8 @@ export function PullRequestDetailPanel({
28782877
fixFindingLabel={handoffLabels.fixFinding}
28792878
{...(canFixFindings ? { onFixFinding: startFixFinding } : {})}
28802879
onRefresh={refreshDetail}
2881-
refreshToken={codeRefreshToken}
2880+
refreshToken={refreshToken}
2881+
backgroundRefreshToken={turnRefresh ?? 0}
28822882
revealRequest={codeRevealRequest}
28832883
/>
28842884
</Suspense>

0 commit comments

Comments
 (0)