Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ function PullRequestCodeTab({
onAddToAgentSelection,
onRefresh,
refreshToken = 0,
backgroundRefreshToken = 0,
revealRequest = null,
}: {
scrollerRef: (node: HTMLDivElement | null) => void;
Expand All @@ -266,6 +267,7 @@ function PullRequestCodeTab({
onAddToAgentSelection?: (input: PullRequestAgentSelectionInput) => void;
onRefresh: () => void;
refreshToken?: number;
backgroundRefreshToken?: number;
revealRequest?: { readonly path: string; readonly nonce: number } | null;
}) {
const { resolvedTheme } = useTheme();
Expand Down Expand Up @@ -308,7 +310,7 @@ function PullRequestCodeTab({

const referenceKey = pullRequestReviewKey(reference);
const commit = selectedCommitOid;
const scopeKey = commit === null ? referenceKey : `${referenceKey}@${commit}`;
const scopeKey = JSON.stringify([environmentId, referenceKey, commit]);
// The panel keeps this mounted across pull requests, so an open composer would otherwise
// survive the switch and attach its comment to whichever one is on screen when it is sent.
const [stateScopeKey, setStateScopeKey] = useState(scopeKey);
Expand Down Expand Up @@ -432,6 +434,15 @@ function PullRequestCodeTab({
refreshFirstDiffPage();
refreshFilesViewed();
}, [refreshToken, scopeKey, refreshFirstDiffPage, refreshFilesViewed]);
const appliedBackgroundRefreshToken = useRef(backgroundRefreshToken);
useEffect(() => {
if (appliedBackgroundRefreshToken.current === backgroundRefreshToken) return;
appliedBackgroundRefreshToken.current = backgroundRefreshToken;
// Keeping slices mounted preserves scroll; the page merge invalidates changed pages.
setSliceState((previous) => ({ ...previous, cursor: null }));
refreshFirstDiffPage();
refreshFilesViewed();
}, [backgroundRefreshToken, refreshFirstDiffPage, refreshFilesViewed]);

// The sentinel is held as state rather than a ref because the viewer mounts its own footer:
// an effect reading a ref could run before that node exists and would never arm the observer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ export function PullRequestDetailPanel({
nativeStackQuery.refresh();
};
const [refreshToken, setRefreshToken] = useState(0);
const codeRefreshToken = refreshToken + (turnRefresh ?? 0);
const [activityRevision, setActivityRevision] = useState<{
readonly key: string;
readonly updatedAt: string;
Expand Down Expand Up @@ -2874,7 +2873,8 @@ export function PullRequestDetailPanel({
fixFindingLabel={handoffLabels.fixFinding}
{...(canFixFindings ? { onFixFinding: startFixFinding } : {})}
onRefresh={refreshDetail}
refreshToken={codeRefreshToken}
refreshToken={refreshToken}
backgroundRefreshToken={turnRefresh ?? 0}
revealRequest={codeRevealRequest}
/>
</Suspense>
Expand Down
Loading