Skip to content

fix(web): restoring a deep Diff panel position no longer crashes on large cached diffs - #42675

Closed
juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-42669
Closed

juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-42669

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

Going back to a thread whose Diff panel was scrolled deep into a large diff (about 200+ expanded files) could crash the app with React error #185 ('Maximum update depth exceeded'). Restoring the scroll position loaded more files from inside React's commit phase. With cached patches, each 4-file batch triggered another nested update until React gave up. The restore now starts each batch after the commit that asked for it, so the position is restored without an update loop.

Fixes #42669

Reproduction on main

Commit ca81b7b (origin/main). Made a scratch git repo with 9 modified and 218 untracked files (227 entries in git status --porcelain -uall). Started T3CODE_DEV_SEED=0 vp run dev on a fresh database, added the repo as a project and created two Replay (dev) threads, Thread A and Thread B. In the web app: opened Thread A, opened the Diff panel, and pressed expand all. 'Diff files collapsed' is on by default, and with every file collapsed the list height is known up front, so nothing loops; the reporter must have had files expanded. Scrolled to the bottom until all 227 patches had loaded (the list grew in batches of 4 to 185,352px). Then clicked Thread B in the sidebar and clicked Thread A again. Result: React logged 'Maximum update depth exceeded', the development wording of minified error #185. Stack: dispatchSetState <- requestFiles (useReviewFilePatches.ts) <- loadNextFiles <- flush (useCodeViewScrollRestore.ts) <- the hook's useEffect. This happened on every first return after a page reload and re-scroll. Later round trips in the same session did not log it. A production web build (vp build, served via vp preview, same steps) restored the position without crashing in 3 round trips, so I did not see the 'Something went wrong' screen myself. That production throw needs the restore updates to run during the commit phase, which the reporter's stack (dispatchSetState -> throwIfInfiniteUpdateLoop from the CodeView onPostRender callback) shows. Failing test pushed: 'restores a deep scroll position in a large cached diff without an update loop' in apps/web/src/components/diffs/useReviewFilePatches.browser.test.tsx. It caches patches for 227 files, saves a scroll position near the bottom, remounts, and calls flush from a layout effect, like the code view's onPostRender. On main it fails with 'Maximum update depth exceeded' thrown from requestFiles <- loadNextFiles <- flush. It passes when loadNextFiles requests every remaining file in one batch (checked with a throwaway change, then reverted).

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

  • vp test run src/components/diffs/useReviewFilePatches.browser.test.tsx on the repro branch before the fix: failed with 'Maximum update depth exceeded' from requestFiles <- loadNextFiles <- flush (reproduced)
  • vp test run src/components/diffs/useReviewFilePatches.browser.test.tsx src/components/diffs/useCodeViewScrollRestore.test.ts src/components/diffs/DiffFileLoadingBoundary.browser.test.tsx after the fix: 3 files, 7 tests passed, no 'Maximum update depth' output
  • vp run check:changed: format, lint, knip, typecheck, tests (2 files), react compiler all pass

Not in this change

  • Restoring a deep position still loads the diff 4 files per batch. With every patch cached it could take larger batches, but that would change how much the panel loads.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

juliusmarminge and others added 2 commits November 25, 2026 07:17
…ff loops

Fails on main: each commit-phase flush loads only four more files, and with
every patch cached each batch settles in the next commit, so 227 files go
past React's nested update limit (#42669).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arge cached diffs

The scroll restore loaded the next batch of files from the code view's
post-render callback, inside React's commit phase. With every patch cached,
each four-file batch settled in the next commit, so a deep position in a diff
of 200+ files chained past React's nested update limit (#42669). Queue the
load in a microtask so each batch starts outside the commit that asked for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The scroll-restoration hook now defers and coalesces load requests in a microtask. Unit and browser tests cover deferred loading and restoring a deep scroll position in a large cached diff.

Changes: Scroll restoration

Layer / File(s) Summary
Deferred and coalesced loading
apps/web/src/components/diffs/useCodeViewScrollRestore.ts, apps/web/src/components/diffs/useCodeViewScrollRestore.test.ts
The hook queues at most one loadMore call in a microtask. The unit test checks that no batch loads before the deferred commit and that one batch loads afterward.
Large-diff restoration test
apps/web/src/components/diffs/useReviewFilePatches.browser.test.tsx
A browser test remounts a viewer with a saved deep scroll position and cached patches for 227 files. It checks that loading advances from 4 files to 222–227 files and that no window errors occur.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to d8c11

This change stops a crash when restoring a deep Diff panel position on large cached diffs. It is covered by new unit and browser tests, and no concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: restoring a deep Diff panel position no longer crashes on large cached diffs. The raw summary shows the fix defers loadMore calls to a microtask, which addresses the R…
Description check Passed The description covers the problem, the change, the scope (links issue #42669 and explains the bug), verification (focused test commands and results), and a note on what is out of scope. It also follo…
Linked Issues check Passed [#42669] The requirement is to stop the React #185 update loop when restoring a deep Diff panel scroll position over a large cached diff. At head, createCodeViewScrollRestore().flush no longer calls l…
Out of Scope Changes check Passed All changed code is tied to the linked issue. The change in useCodeViewScrollRestore.ts defers loadMore through a microtask. The updated useCodeViewScrollRestore.test.ts expects the deferred behavior …
Full details: Title check

Explanation

The title names the main change: restoring a deep Diff panel position no longer crashes on large cached diffs. The raw summary shows the fix defers loadMore calls to a microtask, which addresses the React update-depth crash the title describes. The title follows the conventional commit format from the repository template and stays in plain language.

Full details: Description check

Explanation

The description covers the problem, the change, the scope (links issue #42669 and explains the bug), verification (focused test commands and results), and a note on what is out of scope. It also follows the template's section order. The Evidence section says before/after screenshots are still being captured and that this section must be filled before merge. The UI-change requirement in the template is therefore not yet met. The description also has a sentence on the reporter's stack that is long, but it is still readable.

Full details: Linked Issues check

Explanation

[#42669] The requirement is to stop the React #185 update loop when restoring a deep Diff panel scroll position over a large cached diff. At head, createCodeViewScrollRestore().flush no longer calls loadMore synchronously in the commit phase. When the pending position is out of reach and loading is not settled, flush queues one microtask (coalesced by loadQueued) that calls loadMore. Each batch therefore starts after the commit that requested it, which the issue lists as an acceptable fix. The PR adds a browser regression test (useReviewFilePatches.browser.test.tsx) that seeds 227 cached patches, restores a deep position, and asserts no 'Maximum update depth' error. The PR reports that this test failed on the pre-fix branch and passed after the fix. I did not rerun the tests. The 'Evidence' section (real-app capture) is pending, but it is a manual verification item, not a coding requirement.

Full details: Out of Scope Changes check

Explanation

All changed code is tied to the linked issue. The change in useCodeViewScrollRestore.ts defers loadMore through a microtask. The updated useCodeViewScrollRestore.test.ts expects the deferred behavior (one batch after a microtask). The new browser test covers the 227-file restore case. The PR states that batch size is unchanged, so no unrelated behavior change to the diff loading policy is introduced. No unrelated files or refactors were identified in the PR summary.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • 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 024da4f and d8c1128.

Files selected for processing: 3

  • apps/web/src/components/diffs/useCodeViewScrollRestore.test.ts
  • apps/web/src/components/diffs/useCodeViewScrollRestore.ts
  • apps/web/src/components/diffs/useReviewFilePatches.browser.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@juliusmarminge

Copy link
Copy Markdown
Member Author

The automated pipeline ran the reported steps in the real app without this change, and the problem did not appear. So it cannot show that this change fixes anything.

What was run on ca81b7b97a, the commit before this change:

Created 9 modified and 218 untracked files, each with 40 lines. Opened Thread A, opened Diff, expanded all files, and repeatedly scrolled to the bottom until patch loading and height settled. Captured the deep position, switched to Thread B, confirmed its composer was mounted, waited one second, then returned to Thread A. Checked the crash screen, captured window errors and unhandled rejections, and measured restoration. After a successful run on both commits, repeated with longer cache settling and explicit Thread B confirmation. Final result on both: savedTop 197188, restoredTop 197156, height 198096, no captured exceptions, no crash screen. Base logged only the passive-effect warning. scenarios:prove exited 1 because both sides passed.

How: Scenario runner driving the real web development app in Chromium, 1440x1000, light theme. Each commit used its own fresh database, synthetic git repository, and two Replay (dev) threads.

Closing this pull request. #42669 has been asked for the missing steps; once the problem can be shown this can be reopened, or the fix built again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switching back to a thread whose Diff panel has 200+ files crashes with React #185 in the scroll-restore loop

1 participant