Repository navigation
fix(web): restoring a deep Diff panel position no longer crashes on large cached diffs - #42675
juliusmarminge wants to merge 2 commits into
Conversation
…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>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
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 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. |
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 devon 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 passNot in this change
Who did the work
Run by the t3code factory in T3 Code.