Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): files marked Viewed stay folded when a pull request's Code tab opens again #34168

MergedUmais-Adeed(GitHub profile, opens in a new tab)merged 0 commits intomain fromrefs/pull/34168/headmerged by juliusmarminge View on GitHub

Problem

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

  • isFileDiffCollapsed takes 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 records collapsed = viewed. Reveal (jump to file or line) and Find matches record false.
  • 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.ts covers three cases:

    • folds a file marked Viewed when the Code tab mounts again with no fold choices
    • keeps a reader's choice when the file's Viewed mark loads later
    • withFileDiffFold recording 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 equality

    With 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

    2. @@ -740,6 +740,9 @@
      740740 </div>
      741741 );
      742742
      743+ // 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(
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium pullRequest/PullRequestCodeTab.tsx: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&#39;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.
      
      Umais-Adeed(GitHub profile, opens in a new tab)commented

      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 records collapsed = viewed, a reveal or Find match records false, 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.

      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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 @@
      1616
      1717 export type DiffFoldOverride = "expanded" | "folded" | null;
      1818
      19-/** 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 marked
      21+ * 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;
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium pullRequest/pullRequestDiff.logic.ts: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.

      Suggested change
      29- 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`.
      Umais-Adeed(GitHub profile, opens in a new tab)commented

      Julius fixed this in a5b7e6453c: Viewed marks only set the fold default while foldOverride is null, 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.

    3. 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
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      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.ts
      FileDiffFoldChoices stores absolute per-file states. isFileDiffCollapsed uses 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.tsx
      Code 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 to 9c174

      Viewed files retain the intended fold behavior, and no issue requiring a fix before merge is established.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary web fix: preserving folded state for files marked Viewed when the Code tab reopens.
      Description checkPassedThe 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 checkPassedIssue [#13279] requires a Viewed web Code-tab file to remain folded after reopening the tab. PullRequestCodeTab.tsx now passes the non-stale Viewed state to isFileDiffCollapsed, and `pullRequestDi…
      Out of Scope Changes checkPassedThe 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.tsx now passes the non-stale Viewed state to isFileDiffCollapsed, and pullRequestDiff.logic.ts folds that file when no per-file choice exists. Absolute FileDiffFoldChoices preserve 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

      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.tsx
      • apps/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.

    5. 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.

      BeforeAfter
      Commited52af3a479c174f7f35
      Reopened CodeBefore: Viewed file expandedAfter: Viewed file folded
      Single commitBefore: scope change expands Viewed fileAfter: scope change keeps Viewed file folded
      RecordingBefore interactionAfter interaction

      Explicit expansion still works on head while retaining Viewed:

      After: explicitly expanded Viewed file

      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.
    6. juliusmarminge merged this8cbc959

    7. juliusmarminge closed this

Sign in to join this conversation.