fix(web): restoring a deep Diff panel position no longer crashes on large cached diffs #42675
main fromrefs/pull/42675/head·opened View on GitHubGoing 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 pingdotgg/t3code#42669
Reproduction on main#
Commit ca81b7b97a (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.tsxon 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.tsxafter the fix: 3 files, 7 tests passed, no 'Maximum update depth' outputvp 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.
- 1
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
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.
juliusmarminge closed this
Sign in to join this conversation.
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
apps/web/src/components/diffs/useCodeViewScrollRestore.ts,apps/web/src/components/diffs/useCodeViewScrollRestore.test.tsloadMorecall in a microtask. The unit test checks that no batch loads before the deferred commit and that one batch loads afterward.apps/web/src/components/diffs/useReviewFilePatches.browser.test.tsxEstimated code review effort: 2 (Simple) | ~15 minutes
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk:
Minimal · up to
d8c11This 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:
4
#42669and explains the bug), verification (focused test commands and results), and a note on what is out of scope. It also follo…#42669] The requirement is to stop the React#185update loop when restoring a deep Diff panel scroll position over a large cached diff. At head, createCodeViewScrollRestore().flush no longer calls l…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
#42669and 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#185update 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)
01b07bf0-f3e3-4b58-aa68-15f311a4fe2dReviewing files that changed from the base of the PR and between 024da4f7bfa49973baddb35f39aa95f4ec20222c and d8c1128da8cb95b76f4797115c0556d71ea56376.
apps/web/src/components/diffs/useCodeViewScrollRestore.test.tsapps/web/src/components/diffs/useCodeViewScrollRestore.tsapps/web/src/components/diffs/useReviewFilePatches.browser.test.tsxIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.