Skip to content

Commit 3472adc

Browse files
sameerr03claude
andcommitted
fix(web): PR code view keeps its scroll when a turn finishes
A finished turn anywhere in the environment bumped the same token as the Refresh button, so the Code tab cleared its diff pages, showed the loading state, and remounted the viewer at the top. Turn refreshes now re-read the first page in place; the Refresh button and a new PR revision still start over. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 95030dc commit 3472adc

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ function PullRequestCodeTab({
203203
onAddToAgentSelection,
204204
onRefresh,
205205
refreshToken = 0,
206+
backgroundRefreshToken = 0,
206207
}: {
207208
environmentId: EnvironmentId;
208209
reference: PullRequestRef;
@@ -219,6 +220,11 @@ function PullRequestCodeTab({
219220
onRefresh: () => void;
220221
/** Bumped by the panel's refresh button: drop the accumulated pages and re-read the diff. */
221222
refreshToken?: number;
223+
/**
224+
* Bumped when the diff may have moved without anyone asking, such as a turn finishing
225+
* somewhere in the environment: re-read the first page while the pages on screen stay put.
226+
*/
227+
backgroundRefreshToken?: number;
222228
}) {
223229
const { resolvedTheme } = useTheme();
224230
const settings = useClientSettings();
@@ -437,6 +443,17 @@ function PullRequestCodeTab({
437443
refreshFirstDiffPage();
438444
refreshFilesViewed();
439445
}, [refreshToken, scopeKey, refreshFirstDiffPage, refreshFilesViewed]);
446+
// Emptying the slices here would swap the viewer for the loading state and throw the reader
447+
// back to the top. Pointing at the first page again is enough: an unchanged answer keeps every
448+
// page, and a changed one takes the pages after it along with it.
449+
const appliedBackgroundRefreshToken = useRef(backgroundRefreshToken);
450+
useEffect(() => {
451+
if (appliedBackgroundRefreshToken.current === backgroundRefreshToken) return;
452+
appliedBackgroundRefreshToken.current = backgroundRefreshToken;
453+
setSliceState((previous) => ({ ...previous, cursor: null }));
454+
refreshFirstDiffPage();
455+
refreshFilesViewed();
456+
}, [backgroundRefreshToken, refreshFirstDiffPage, refreshFilesViewed]);
440457
const nextCursor = loadedSlices.at(-1)?.nextCursor ?? null;
441458
// What a slice withheld: the host declining to inline part of it, or a patch the viewer could
442459
// not structure and so dropped. Neither says anything about there being more to fetch.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,6 @@ export function PullRequestDetailPanel({
818818
nativeStackQuery.refresh();
819819
}, [activityQuery.refresh, detailQuery.refresh, nativeStackQuery.refresh]);
820820
const [refreshToken, setRefreshToken] = useState(0);
821-
const codeRefreshToken = refreshToken + (turnRefresh ?? 0);
822821
const activityRevision = useRef<{ readonly key: string; readonly updatedAt: string } | null>(
823822
null,
824823
);
@@ -2774,7 +2773,8 @@ export function PullRequestDetailPanel({
27742773
fixFindingLabel={handoffLabels.fixFinding}
27752774
onFixFinding={startFixFinding}
27762775
onRefresh={refreshDetail}
2777-
refreshToken={codeRefreshToken}
2776+
refreshToken={refreshToken}
2777+
backgroundRefreshToken={turnRefresh ?? 0}
27782778
/>
27792779
</Suspense>
27802780
</div>

0 commit comments

Comments
 (0)