Skip to content

fix(combined-diff): an image row loads in its own boundary so the combined diff can't loop into React #185 - #31552

Merged
nwparker merged 1 commit into
mainfrom
crash-scan45/react185
Nov 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
crash-scan45/react185

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​92 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​92
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

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:

  • Active tab is an editor, with Source Control in the right sidebar.
  • Stacks run through CombinedDiffViewer's toolbar.
  • 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_END layout effect of a toolbar Popover or the file-tree Popover. They are not the cause.

  • Reproduced on origin/main (57bc1778dc1) in a hidden dev Electron, driven through openAllDiffs. Fixture B (7 modified binaries plus a modified z.png in the off-screen extra rows) crashed 3/3 runs with Maximum update depth exceeded … setRef … in the <button> component, the same as report 48c830ba. Fixture A (7 modified .ts files plus z.png) crashed 4/4 runs: fix: improve scrollbar and file explorer scroll behavior #185 first, then InstantiationService has been disposed ×24. Control: when z.png is outside the extra-row budget, there is no crash.
  • With this fix: fixture A gave 3/3 clean runs (9 rows, 2 images rendered). Fixture B was clean on 7 of 8 runs; the one failure was the first run after switching, before the dev bundle rebuilt. Reverting the fix brings the crash back.
  • Rebased onto origin/main be1fceb69db. The only conflict was in imports and context: main had added the DiffTooLargeNotice branch. The prod change is unchanged.
  • Tests: pnpm test src/renderer/src/components/editor/DiffSectionBody gives 2 files and 4 tests passed. With origin/main's DiffSectionBody.tsx restored, the image-suspense test fails with expected <div data-testid="editor-fallback"></div> to be null. pnpm check:changed --maxWorkers=2: 24 checks passed.
  • Adversarial review (scan 62): 1 loop, clean. The reviewer confirmed that nothing else in a combined-diff row can suspend to the editor boundary: Monaco loads via its loader, theme and plugin-syntax hooks use effects, and comment cards are separate roots. The 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.workbench error boundary. In each report the component stack is button <- TooltipTrigger <- Tooltip, the toolbar button that happened to be updating when React's counter ran out:

Report id Platform
ba710cce-9b6a-42c5-8bbb-e0e78c8d7216 Linux x64
ab160e15-5bbf-4711-8f36-d5d08f32cfde macOS arm64
8614fdd4-6422-4b26-b0c2-65181fef11bf macOS arm64

Not covered: the Windows React #185 reports with a focus-group / TooltipProvider stack (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: DiffSectionBody renders the lazy-loaded ImageDiffViewer, which is the only lazy component in a combined-diff row. Before this change, its loading state went up to the editor-level Suspense, and that boundary hides the whole editor. With the list hidden, its scroll container measures clientHeight = 0. getCombinedDiffRenderRange caps 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 (Radix composeRefs -> 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

  • The fix is at the source of the loop. The loop exists only because a row's loading state hides the list that decides whether that row exists. A boundary local to the row removes that dependency for every caller of DiffSectionBody: the editor combined diff, the PR page, and the PR dialog combined diff.
  • Alternatives considered:
    • Preloading the image chunk only narrows the window. A slow or failed fetch would still start the loop.
    • Making the virtualizer ignore a zero clientHeight treats the symptom and leaves other lazy content open to the same problem.
    • Guarding the Tooltip ref callbacks would only hide the bystander that React's counter happened to land on.

Fix evidence

Re-verification in scan 47 (2026-10-22, PR rebased onto origin/main ec5eaf96c17, new head 0ec7631d99c)

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):

Run Result
After fix: binary fixture (b1..b7.dat, zz/a.png, zz/bicycle.png) 3 of 3 clean. max #185 count = 0, 0 errors, all 9 rows rendered, 3 <img>s shown
After fix: .ts fixture 2 of 2 clean. 0 errors, 8 rows, 4 <img>s
Fix reverted again: .ts fixture Crashed again: 24 errors, 0 rows rendered

All 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.tsx gives Tests 1 failed (expected <div data-testid="editor-fallback"></div> to be null) with origin/main's DiffSectionBody.tsx and Tests 1 passed with this PR's. Together with DiffSectionBody.word-wrap-lifecycle.test.tsx: 2 files, 4 tests passed. oxlint on both changed files: clean.

Rendered app reproduction (before / after / revert)

Setup:

  • Dev app driven through CDP, running hidden (ORCA_BACKGROUND_LAUNCH=1), with CDP on port 9371 and Vite on 5291.
  • Isolated HOME and ORCA_DEV_USER_DATA_PATH under /tmp/scan45/rigs/react185.
  • Built from origin/main fd8b2dc3a7c.
  • Fixture repo with 7 modified .ts files, a modified z.png (it sorts after the .ts files, so it lands in the off-screen extra rows) and an untracked new.ts.
  • The driver reloads the app, calls store.openAllDiffs(worktreeId, path) and scrolls.
Run Result
Before fix 5 of 5 crashed. Twice it was Error: Maximum update depth exceeded at getRootForUpdatedFiber <- enqueueConcurrentHookUpdate <- dispatchSetStateInternal <- dispatchSetState <- setRef <- (composeRefs) Array.map <- setRef, with component stack button <- Button <- Primitive.button.Slot <- Primitive.button <- Primitive.div.Slot <- PopperAnchor <- TooltipTrigger <- Tooltip <- div <- div <- CombinedDiffToolbar <- CombinedDiffViewer <- EditorContent <- Suspense <- EditorPanelShell <- ... <- TabGroupPanel, contained by terminal.workbench. This matches the production reports frame for frame. The other 3 runs threw InstantiationService has been disposed from the same flip.
Control: no image file No crash
Control: the image is the first, visible row (0.png) No crash, and the image rendered
After fix (applied by HMR) 3 of 3 clean. No errors, all 9 rows rendered, and the image diff showed 2 <img>s
Fix reverted Crash came back in 3 of 3 runs
Fix restored Clean again

Regression test

src/renderer/src/components/editor/DiffSectionBody.image-suspense.test.tsx holds the ImageDiffViewer chunk pending inside an outer Suspense, then checks that the outer fallback never appears.

  • Without the fix (origin/main DiffSectionBody.tsx), it fails:
    AssertionError: expected <div data-testid="editor-fallback"> to be null
    
    This means the outer boundary hid the list.
  • With the fix: it passes.

Testing

  • pnpm tc:web: no type errors (15,339 files), run on the original head b2e18fa8f09. 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.ts on DiffSectionBody.image-suspense.test.tsx, DiffSectionBody.word-wrap-lifecycle.test.tsx and EditorContent.test.tsx: 3 files, 10 tests passed. The new test fails without the fix.

  • oxlint on both changed files is clean, and oxfmt made 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

  • Until the image viewer chunk loads for the first time, that one image row is briefly empty (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.
  • No other behavior changes. A failed chunk load reaches the same error path as before.
  • This PR does not address the Windows focus-group React fix: improve scrollbar and file explorer scroll behavior #185 reports (9fa4071e, b24d265c). They stay open and unreproduced.

Adversarial review

1 loop, final result: clean (no P0 or P1 problems).

  • The regression test catches the bug. It passes with the fix and fails when origin/main's DiffSectionBody.tsx is restored, because the outer fallback rendered.
  • The root-cause story matches the code. getCombinedDiffRenderRange caps its off-screen rows at clientHeight. 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.
  • The fix is in the right place. ImageDiffViewer is the only lazy component in DiffSectionBody / DiffSectionItem, and Monaco's DiffEditor doesn'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.
  • No regressions found. The change is renderer-only, with no SSH, folder-workspace, Windows/Linux, or older-peer compatibility effect. There are no casts and no lint-rule disables.

Scan 47 re-review: 1 loop, clean (no P0, P1 or real P2 findings). It re-checked every caller (DiffSectionBody is used only by DiffSectionItem, 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: DiffSectionBody creates its own lazy ImageDiffViewer instead of the shared one in editor-lazy-views.ts. That was already on main and is unrelated to the crash.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security, mobile and backwards compatibility: no impact. This is a renderer-only change to one React component and adds one test.
  • Cross-platform: the code is platform-independent, and the crash reports came from Linux and macOS.
  • SSH and folder workspaces: unaffected. The combined-diff rendering is the same for every host type.
  • Performance: no measurable change. It adds one Suspense boundary per image row.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

… 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.
@nwparker
nwparker force-pushed the crash-scan45/react185 branch from 6cfa16e to 7daf3b3 Compare November 3, 2026 05:24
@nwparker
nwparker marked this pull request as ready for review November 3, 2026 05:46
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

DiffSectionBody now wraps the binary image viewer in a Suspense boundary with a null fallback. A new test checks that the outer fallback remains absent and the diff-list sibling remains visible while the image chunk is pending. After the chunk resolves, the test checks that the image viewer appears.

Merge Risk: Minimal · up to 7daf3

The local Suspense boundary preserves the diff list while the image loads, with no remaining concrete merge-blocking risk identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the change (a row-local Suspense boundary for the image row in the combined diff) and the crash it fixes (React #185). It is specific and matches the code change. Its length (106 chara…
Description check Passed The description follows the repository template closely. It has an ELI5 section, a What Changed section with before and after and mechanism, a Why section with alternatives, a Linked Issue section, a …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change (a row-local Suspense boundary for the image row in the combined diff) and the crash it fixes (React #185). It is specific and matches the code change. Its length (106 characters) is long, and it contains an issue number, but the primary change is clear.

Full details: Description check

Explanation

The description follows the repository template closely. It has an ELI5 section, a What Changed section with before and after and mechanism, a Why section with alternatives, a Linked Issue section, a Visual Proof section marked N/A with a reason, a Testing section with a manual-test checkbox and automated test evidence, a Risk section, and the Notes and Checklist sections. Gaps: the Linked Issue section reads 'Fixes #' with no issue number. The Risk section has no 'Level' selection (the field reads 'Level: <!-- Low, Medium, or High -->' with no value). The AI Disclosure section is left as template text. The Review section has no content beyond the boundary checkbox. The Checklist leaves the final 'pnpm lint, typecheck, test, build' item unchecked. The description also contains a long run of scan-log detail that makes the PR harder to scan. The Risk section does not name a revert path explicitly. The core template content is present and the technical reasoning is strong.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/cpp/security/world-writable-file-cpp.yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 76c927b1-3919-454c-80ab-da175057e2dc
Commits

Reviewing files that changed from the base of the PR and between bff4e36 and 7daf3b3.

Files selected for processing: 2
  • src/renderer/src/components/editor/DiffSectionBody.image-suspense.test.tsx
  • src/renderer/src/components/editor/DiffSectionBody.tsx

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

@nwparker
nwparker merged commit 896e2d2 into main Nov 3, 2026
69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants