Repository navigation
fix(combined-diff): an image row loads in its own boundary so the combined diff can't loop into React #185 - #31552
Conversation
b2e18fa to
0ec7631
Compare
0ec7631 to
6cfa16e
Compare
… list can't loop into React #185 The image viewer chunk is lazy. Its first load suspended to the editor panel's boundary, which hid the whole virtualized combined diff. Hidden, the list dropped the overscan image row, stopped suspending and re-showed; shown, it rendered the row again and re-suspended. Each flip re-attached ref callbacks (the toolbar's 'Show file tree' tooltip trigger first), so the synchronous commits ran past React's nested-update limit (or tore down Monaco mid-mount). A row-local Suspense keeps the chunk load inside the image section.
6cfa16e to
7daf3b3
Compare
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
ELI5
The combined diff is a long list that only draws the rows near the screen. The first time it reached an image file, it had to download the code for the image viewer. While that code loaded, React hid the whole list. A hidden list thinks the screen is zero pixels tall, so it stopped drawing the image row. With no image row, nothing was loading any more, so React showed the list again. Once the list was showing, it drew the image row again, and that hid everything again. This flipped back and forth so fast that React gave up and crashed. The fix puts a small "loading" boundary around just the image row. Now loading the image code never hides the rest of the list, so the flipping can't start.
Description
This fixes the React #185 crash ("Maximum update depth exceeded") that 1.4.237 users hit when they open "all changes" (the combined diff) in a change set that has an image file below the first screen of rows.
Scan 62 update (v1.4.245): still crashing users, rebased
This crash is still live on the current release. On v1.4.245, 3 different users hit React #185 in the combined diff on 2026-10-30: macOS 25.6, macOS 27.0 and Linux Ubuntu (kernel 7.0). Report IDs:
2fb72d7a-d59b-42e6-8520-b89b017ba05d,3696ece1-ed6d-43ab-857f-a52f1ea3bc85,48c830ba-f324-4994-88b6-af00c192b4cb.What all three reports share:
react_commit_cascade commits=40 storeWrites=0, which means a local React loop, not a store loop.The named components are bystanders that tripped React's counter: the toolbar Tooltip button, and the Presence
ANIMATION_ENDlayout effect of a toolbar Popover or the file-tree Popover. They are not the cause.57bc1778dc1) in a hidden dev Electron, driven throughopenAllDiffs. Fixture B (7 modified binaries plus a modifiedz.pngin the off-screen extra rows) crashed 3/3 runs withMaximum update depth exceeded … setRef … in the <button> component, the same as report48c830ba. Fixture A (7 modified.tsfiles plusz.png) crashed 4/4 runs: fix: improve scrollbar and file explorer scroll behavior #185 first, thenInstantiationService has been disposed×24. Control: whenz.pngis outside the extra-row budget, there is no crash.be1fceb69db. The only conflict was in imports and context: main had added theDiffTooLargeNoticebranch. The prod change is unchanged.pnpm test src/renderer/src/components/editor/DiffSectionBodygives 2 files and 4 tests passed. With origin/main'sDiffSectionBody.tsxrestored, the image-suspense test fails withexpected <div data-testid="editor-fallback"></div> to be null.pnpm check:changed --maxWorkers=2: 24 checks passed.fallback={null}row causes at most one resize, because the chunk is cached after its first load. The test was re-verified to fail without the fix.Please land this one. It is the only open fix for the most frequent macOS/Linux React crash in the combined diff.
Crash reports
React #185 on v1.4.237, contained by the
terminal.workbencherror boundary. In each report the component stack isbutton <- TooltipTrigger <- Tooltip, the toolbar button that happened to be updating when React's counter ran out:ba710cce-9b6a-42c5-8bbb-e0e78c8d7216ab160e15-5bbf-4711-8f36-d5d08f32cfde8614fdd4-6422-4b26-b0c2-65181fef11bfNot covered: the Windows React #185 reports with a focus-group /
TooltipProviderstack (9fa4071e-3edd-4a68-823e-ac08f6181a50,b24d265c-4d48-4129-a681-d750bc5e88d9). Their stack is different, I could not reproduce them, and they stay open.What Changed
Before: if you opened the combined diff and an image file (for example
z.png) fell just below the visible rows, the editor area crashed and showed the error screen.After: the list renders normally. Until the image viewer code finishes loading the first time, the image row stays briefly empty, and then the image diff appears.
Mechanism:
DiffSectionBodyrenders the lazy-loadedImageDiffViewer, which is the only lazy component in a combined-diff row. Before this change, its loading state went up to the editor-levelSuspense, and that boundary hides the whole editor. With the list hidden, its scroll container measuresclientHeight = 0.getCombinedDiffRenderRangecaps its extra off-screen rows at that height, so the image row was dropped. Dropping the row un-suspended the editor, the list became visible again, it re-added the image row, and that suspended the editor again. Every flip re-attached refs (RadixcomposeRefs->setRef->setState), and this went on until React threw #185. This PR wraps the image viewer in a row-local<Suspense fallback={null}>, so a pending image chunk never hides the list and the cycle can't start.Why
DiffSectionBody: the editor combined diff, the PR page, and the PR dialog combined diff.clientHeighttreats the symptom and leaves other lazy content open to the same problem.Fix evidence
Re-verification in scan 47 (2026-10-22, PR rebased onto origin/main
ec5eaf96c17, new head0ec7631d99c)Rendered dev app, hidden, driven through CDP on port 9383 (
node /tmp/scan47/rigs/react185/scripts/ev.mjs setup.js && node ev.mjs open.js):b1..b7.dat,zz/a.png,zz/bicycle.png)<img>s shown.tsfixture<img>s.tsfixtureAll rig processes were killed afterwards and port 9383 is down.
Unit test on the rebased head:
node config/scripts/run-vitest.mjs run --config config/vitest.config.ts src/renderer/src/components/editor/DiffSectionBody.image-suspense.test.tsxgives Tests 1 failed (expected <div data-testid="editor-fallback"></div> to be null) with origin/main'sDiffSectionBody.tsxand Tests 1 passed with this PR's. Together withDiffSectionBody.word-wrap-lifecycle.test.tsx: 2 files, 4 tests passed.oxlinton both changed files: clean.Rendered app reproduction (before / after / revert)
Setup:
ORCA_BACKGROUND_LAUNCH=1), with CDP on port 9371 and Vite on 5291.HOMEandORCA_DEV_USER_DATA_PATHunder/tmp/scan45/rigs/react185.origin/mainfd8b2dc3a7c..tsfiles, a modifiedz.png(it sorts after the.tsfiles, so it lands in the off-screen extra rows) and an untrackednew.ts.store.openAllDiffs(worktreeId, path)and scrolls.Error: Maximum update depth exceededatgetRootForUpdatedFiber <- enqueueConcurrentHookUpdate <- dispatchSetStateInternal <- dispatchSetState <- setRef <- (composeRefs) Array.map <- setRef, with component stackbutton <- Button <- Primitive.button.Slot <- Primitive.button <- Primitive.div.Slot <- PopperAnchor <- TooltipTrigger <- Tooltip <- div <- div <- CombinedDiffToolbar <- CombinedDiffViewer <- EditorContent <- Suspense <- EditorPanelShell <- ... <- TabGroupPanel, contained byterminal.workbench. This matches the production reports frame for frame. The other 3 runs threwInstantiationService has been disposedfrom the same flip.0.png)<img>sRegression test
src/renderer/src/components/editor/DiffSectionBody.image-suspense.test.tsxholds theImageDiffViewerchunk pending inside an outerSuspense, then checks that the outer fallback never appears.DiffSectionBody.tsx), it fails:Testing
pnpm tc:web: no type errors (15,339 files), run on the original headb2e18fa8f09. Not re-run after the scan 47 rebase because the local install was broken; the diff is unchanged.node config/scripts/run-vitest.mjs run --config config/vitest.config.tsonDiffSectionBody.image-suspense.test.tsx,DiffSectionBody.word-wrap-lifecycle.test.tsxandEditorContent.test.tsx: 3 files, 10 tests passed. The new test fails without the fix.oxlinton both changed files is clean, andoxfmtmade no changes.pnpm run check:code-quality:changed: 0 new findings across every gate.Pre-commit hooks (oxlint, react-doctor, oxfmt) passed.
Rendered dev app on macOS: crash before the fix (5 of 5), clean after it (3 of 3), and the crash came back when the fix was reverted (3 of 3).
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Visual Proof
N/A. The only visible change is that the editor no longer crashes. The rendered-app evidence above is from runs driven through CDP in a hidden window.
Trade-offs
fallback={null}) instead of the whole editor showing its loading fallback. This is a better experience in practice. The virtualizer re-measures the row once the image appears.9fa4071e,b24d265c). They stay open and unreproduced.Adversarial review
1 loop, final result: clean (no P0 or P1 problems).
DiffSectionBody.tsxis restored, because the outer fallback rendered.getCombinedDiffRenderRangecaps its off-screen rows atclientHeight. When the list is hidden, that height is 0, which drives the drop-row / un-suspend / re-show / re-suspend loop. Each re-show re-attaches refs.ImageDiffVieweris the only lazy component inDiffSectionBody/DiffSectionItem, and Monaco'sDiffEditordoesn't suspend. All callers are covered: the editor combined diff, the PR page, and the PR dialog. The single-file image diff (EditorDiffFileSurface) uses its own lazy views and is unaffected.Scan 47 re-review: 1 loop, clean (no P0, P1 or real P2 findings). It re-checked every caller (
DiffSectionBodyis used only byDiffSectionItem, which is shared by the editor combined diff and the PR page combined diff; nothing else in a row is lazy), confirmed the test fails on origin/main and passes here, and confirmed a failed chunk load still reaches the existing error boundary. Minor note, not changed here:DiffSectionBodycreates its own lazyImageDiffViewerinstead of the shared one ineditor-lazy-views.ts. That was already on main and is unrelated to the crash.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)