fix(web): files marked Viewed stay folded when a pull request's Code tab opens again #34168
main fromrefs/pull/34168/head·merged by juliusmarminge View on GitHubProblem#
In a pull request's Code tab, marking a file Viewed folds it. If you close the right panel (or open another right-panel tab) and come back, or change the commit scope, every file is expanded again while its Viewed tick stays. Reviewers working through several PRs lose their place, as okaisti describes in #13279. screen-gd, Mnigos and moinmir reproduced it on nightlies up to 0.1.4-nightly.20261028.3824, and Mnigos recorded the remount path.
PullRequestCodeTab keeps fold state only as toggledFiles and foldOverride in local state. A remount starts both empty, and a scope change clears them. isFileDiffCollapsed decides folding from those two alone, so the persisted Viewed marks never feed into it.
Change#
isFileDiffCollapsedtakes whether the file is viewed. A viewed, non-stale file is folded by default. A stale mark means the file changed after it was viewed, so it opens like any other file.- A reader's own fold choice is stored per file as an absolute value (
FileDiffFoldChoices), not as a toggle relative to the default. So a Viewed mark that loads or changes after the reader folds or unfolds a file doesn't flip their choice. Ticking or unticking Viewed recordscollapsed = viewed. Reveal (jump to file or line) and Find matches recordfalse. - Fold all and Expand all clear the per-file choices, so later pages follow the toolbar as before. Viewed marks only set the default while no toolbar override is active (Julius's a5b7e6453c), so Expand all opens viewed files too.
- Marks are read through the existing optimistic overlay, so ticking a file folds it in the same render.
The "collapse diffs by default" setting works as before.
Scope and approval#
Fixes #13279, which is labelled via-triage and reproduced by several users. This is the same approach as the earlier #13280, which its author closed only to trim their queue. It is rewritten here against current main.
Mobile has its own PR diff view with separate collapse state (PullRequestRouteScreen.tsx). I left it unchanged because I can't verify a native change without a device, and it's better as its own fix.
Verification#
pullRequestDiff.logic.test.tscovers three cases:folds a file marked Viewed when the Code tab mounts again with no fold choiceskeeps a reader's choice when the file's Viewed mark loads laterwithFileDiffFoldrecording absolute choices
Against main's logic, the first two fail:
× folds a file marked Viewed when the Code tab mounts again with no fold choices AssertionError: expected false to be true // Object.is equality × keeps a reader's choice when the file's Viewed mark loads later AssertionError: expected true to be false // Object.is equalityWith the change, all 8 tests in the file pass.
PullRequestCodeTab.browser.test.tsx: 5 tests pass.vp run check:changed: format, lint, knip, typecheck, tests and the React Compiler check pass.This is a state bug, so the proof is the logic test. I did not record a before/after video against a live GitHub pull request. The reporter's recording in the issue shows the before state.
An earlier CI run failed in
useInlineActionConfirm.browser.test.tsx(enable auto-merge), which this change doesn't touch.
Written by Claude Opus 5.5 in Claude Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -740,6 +740,9 @@740740 </div>741741 );742742743+ // A stale mark means the file changed since it was viewed, so it opens like any other file.744+ const foldsAsViewed = (path: string) =>745+ filesViewedEnabled && isFileViewed(path) && !isFileViewedStale(path);743746 const items: CodeViewDiffItem<ReviewAnnotationGroup>[] = annotatedFiles.map(744747 ({ fileKey, path, fileDiff, annotations, annotationsVersion }) => {745- const collapsed = isFileDiffCollapsed(fileKey, effectiveFoldOverride, toggledFiles);748+ const collapsed = isFileDiffCollapsed(
🟡 Medium
pullRequest/PullRequestCodeTab.tsx:748A reader's explicit fold choice is reversed when a file's Viewed state changes asynchronously, so a viewed file can reopen or a dismissed file can become hidden.
toggledFilesis interpreted relative to the currentfoldsAsViewed(path)default, but background refreshes and late Viewed-mark results preserve the toggles; preserve explicit choices independently of that changing default or rebase them when it changes.Also found in 1 other location(s)
apps/web/src/components/pullRequest/pullRequestDiff.logic.ts:29The toggle set is now interpreted against a default that can change asynchronously.
usePullRequestFilesViewedtreats a missing query result as unviewed (toFileViewedStates(null)andisFileViewed), independently of diff loading. If a reader manually folds a file before its persisted Viewed mark arrives, its key is added totoggledFiles; when the mark arrives, this expression flips the same key to expanded. No scope reset or rebasing occurs for that update, so loading Viewed marks can undo a reader's explicit fold and reopen a viewed file. Preserve explicit per-file choices when the viewed default changes.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/pullRequest/PullRequestCodeTab.tsx around line 748: A reader's explicit fold choice is reversed when a file's Viewed state changes asynchronously, so a viewed file can reopen or a dismissed file can become hidden. `toggledFiles` is interpreted relative to the current `foldsAsViewed(path)` default, but background refreshes and late Viewed-mark results preserve the toggles; preserve explicit choices independently of that changing default or rebase them when it changes. Also found in 1 other location(s): - apps/web/src/components/pullRequest/pullRequestDiff.logic.ts:29 -- The toggle set is now interpreted against a default that can change asynchronously. `usePullRequestFilesViewed` treats a missing query result as unviewed (`toFileViewedStates(null)` and `isFileViewed`), independently of diff loading. If a reader manually folds a file before its persisted Viewed mark arrives, its key is added to `toggledFiles`; when the mark arrives, this expression flips the same key to expanded. No scope reset or rebasing occurs for that update, so loading Viewed marks can undo a reader's explicit fold and reopen a viewed file. Preserve explicit per-file choices when the viewed default changes.Fixed in a96349169f, on top of Julius's a5b7e6453c. Fold choices are now stored as absolute per-file values (
FileDiffFoldChoices, a map from file to collapsed) instead of toggles relative to the default, so a Viewed mark that loads or changes later no longer flips a reader's choice. Ticking or unticking Viewed recordscollapsed = viewed, a reveal or Find match recordsfalse, and Fold all / Expand all clear the choices so later pages follow the toolbar. New case:keeps a reader's choice when the file's Viewed mark loads later.Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Sorry, I'm unable to act on this request because you do not have permissions within this repository.
@@ -16,10 +16,14 @@16161717 export type DiffFoldOverride = "expanded" | "folded" | null;181819-/** Keep fold choices relative to the toolbar so later pages inherit Fold all. */19+/**20+ * Keep fold choices relative to the toolbar so later pages inherit Fold all. A file still marked21+ * Viewed starts folded, so it reopens folded after the fold choices reset.22+ */2023 export function isFileDiffCollapsed(2124 fileKey: string,2225 foldOverride: DiffFoldOverride,2326 toggledFileKeys: ReadonlySet<string>,27+ viewed = false,2428 ): boolean {25- const foldedByDefault = foldOverride === "folded";29+ const foldedByDefault = foldOverride === "folded" || viewed;🟡 Medium
pullRequest/pullRequestDiff.logic.ts:29Setting
foldOverrideto"expanded"still leaves every viewed file collapsed, soExpand all filesdoes nothing when all files are viewed.viewedis ORed into the default regardless of the toolbar override; apply the viewed default only whenfoldOverrideisnull.Suggested change29- const foldedByDefault = foldOverride === "folded" || viewed;29+ const foldedByDefault = foldOverride === "folded" || (foldOverride === null && viewed);🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/pullRequest/pullRequestDiff.logic.ts around line 29: Setting `foldOverride` to `"expanded"` still leaves every viewed file collapsed, so `Expand all files` does nothing when all files are viewed. `viewed` is ORed into the default regardless of the toolbar override; apply the viewed default only when `foldOverride` is `null`.Julius fixed this in a5b7e6453c: Viewed marks only set the fold default while
foldOverrideisnull, so Fold all and Expand all outrank them. a96349169f keeps that behavior.Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — Viewed files now reopen collapsed unless their Viewed marks are stale, changing the default Code-tab review experience. Human review is required for that default change; separate Medium findings concern explicit fold choices and Expand all behavior.
Needs human approval because:
- 2 blocking correctness issues found at or above your repo's Minimum Blocking Severity
No actionable comments were generated in the recent review.
Walkthrough
-
Per-file fold choices store absolute collapsed or expanded states. Non-stale Viewed files fold by default when no global override applies. Code tab actions update or clear choices for toggles, Viewed-state changes, reveals, search matches, and pull-request scope changes.
Changes: Viewed-file folding
Layer / File(s) Summary Per-file fold model
apps/web/src/components/pullRequest/pullRequestDiff.logic.ts,apps/web/src/components/pullRequest/pullRequestDiff.logic.test.tsFileDiffFoldChoicesstores absolute per-file states.isFileDiffCollapseduses an explicit choice first, then the global fold override or Viewed status. Tests cover explicit choices, Viewed defaults, and unchanged choices.Code tab fold updates
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx,apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsxCode tab actions update choices for toggles, Viewed-state changes, reveals, and search matches. The tab clears choices after Fold all or Expand all and when the pull-request scope changes. Stale Viewed marks do not trigger folding. A browser test verifies that a revealed file stays expanded when its Viewed mark arrives later. Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Suggested reviewers:
juliusmarminge,maria-rcks
Merge Risk:
Minimal · up to9c174-
Viewed files retain the intended fold behavior, and no issue requiring a fix before merge is established.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary web fix: preserving folded state for files marked Viewed when the Code tab reopens. Description check The description is complete and structured with Problem, Change, Scope and approval, and Verification sections. It explains the bug, implementation, scope limits, linked issue, tests, reported results… Linked Issues check Issue [ #13279] requires a Viewed web Code-tab file to remain folded after reopening the tab.PullRequestCodeTab.tsxnow passes the non-stale Viewed state toisFileDiffCollapsed, and `pullRequestDi…Out of Scope Changes check The changes stay within the web pull-request Code-tab fold behavior for [ #13279]. Stale marks, reveal and Find expansion, toolbar reset, and pagination support the same fold-state fix. The added tests…Full details: Description check
-
Explanation
The description is complete and structured with Problem, Change, Scope and approval, and Verification sections. It explains the bug, implementation, scope limits, linked issue, tests, reported results, and known unrelated CI failure. It also states that no live before/after video was recorded, but this does not prevent the description from being mostly complete.
Full details: Linked Issues check
-
Explanation
Issue [
#13279] requires a Viewed web Code-tab file to remain folded after reopening the tab.PullRequestCodeTab.tsxnow passes the non-stale Viewed state toisFileDiffCollapsed, andpullRequestDiff.logic.tsfolds that file when no per-file choice exists. AbsoluteFileDiffFoldChoicespreserve a reader's choice when Viewed state loads later. The logic and browser tests cover remount folding and delayed Viewed state.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within the web pull-request Code-tab fold behavior for [
#13279]. Stale marks, reveal and Find expansion, toolbar reset, and pagination support the same fold-state fix. The added tests verify the changed behavior. No unrelated feature change is shown, and the separate mobile diff view remains unchanged.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: ed52af3
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
d517833e-e688-4112-867e-f394652ed72b
Commits-
Reviewing files that changed from the base of the PR and between a96349169f17d03b9b9243c30f4a81ce0a6b7d7d and 9c174f7f355af036631a089e30946acf37827814.
Files selected for processing: 2-
apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsxapps/web/src/components/pullRequest/PullRequestCodeTab.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
-
-
Evidence#
Real web app, Chromium, 1280×800 CSS pixels, light theme, fresh isolated state, synthetic PR API fixture; no production source modifications or live forge writes.
Set Default diff file state to Expanded → open PR Code → mark src/footer.ts Viewed → close and reopen the right panel → select Code → switch All commits to the single commit and back. Base retains the Viewed tick but expands the file; head keeps it folded.
Before After Commit ed52af3a47 9c174f7f35 Reopened Code 

Single commit 

Recording Before interaction After interaction Explicit expansion still works on head while retaining Viewed:

Seed script · Synthetic forge fixture · Reproduction instructions
AI-assisted; verified with the tests and tools listed above.
Not shown:
- Desktop shell was not exercised; this proof covers the real web client.
- Stale Viewed marks after file-content changes and deliberately delayed mark-loading races were not exercised.
juliusmarminge merged this8cbc959
juliusmarminge closed this
Umais-Adeed(GitHub profile, opens in a new tab) linked this to fix #13279
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed