Repository navigation
fix(terminal): stop measure<->fit feedback loop in overlay fallback (React #185) - #10026
Conversation
📝 WalkthroughWalkthroughUpdated 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
…React #185) The TerminalOverlaySlot fallback-measurement path (Windows/Chromium without full CSS anchor-size support) installed a ResizeObserver whose callback wrote a brand-new measuredFallbackRect object on every tick with no equality guard. A stable geometry therefore still "changed" state each measurement, re-running the second layout effect -> SYNC_FIT_PANES_EVENT -> xterm fit() -> resize -> observe -> repeat: an unbounded measure<->fit loop that crashed with React #185 ("Maximum update depth exceeded"). macOS takes the CSS-anchor path where the measuring effect early-returns, which is why it never crashed. Round measured top/left/width/height to integers (kills sub-pixel jitter) and return the previous state reference on an unchanged rect so React bails out and the loop settles. Also guard the null-reset branch to only commit when prev is not already null. Genuine geometry changes are unaffected. Adds a happy-dom regression test that forces the fallback path and drives the ResizeObserver with a constant rect: buggy HEAD re-renders once per tick (unbounded), the fix settles at zero. Reports: Windows, Orca 1.4.148/1.4.149, boundary terminal.workbench, React #185 (f1783c09 / 5ff8a4e6 / 52aabedb).
e1b264c to
dfc4b1d
Compare
nwparker
left a comment
There was a problem hiding this comment.
Reviewed final dfc4b1d: precise tolerance-based geometry guard, expanded React #185 regression coverage, full terminal-pane suite, web typecheck/lint, Windows restart regressions, and packaged crash-survival harness are green. The verify failure is the repository-wide stale skill-manifest base issue tracked by #10030.
Coalesce identical and sub-pixel fallback overlay measurements so ResizeObserver and xterm fit cannot sustain a render feedback loop, while preserving precise committed geometry. Adds regression coverage for stable measurements, sub-pixel jitter across integer boundaries, and genuine resizes.
Description
Fixes a Windows-only React error #185 ("Maximum update depth exceeded") crash in the terminal workbench (error boundary
terminal.workbench), reported on Orca 1.4.148 / 1.4.149.Root cause is in
TerminalOverlaySlot(src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.tsx), specifically the fallback-measurement path that runs when CSS anchor positioning is unavailable. On Windows/Chromium configs lacking fullanchor-size()support,shouldUseCssAnchorPositioning()returnsfalse, so the app takes the fallback path (macOS takes the CSS-anchor path where the measuring effect early-returns — which is why macOS never crashed).On the fallback path, the first layout effect installs a
ResizeObserverwhose callbackupdateRect()calledsetMeasuredFallbackRect({ top, left, width, height })with a brand-new object every tick and no equality guard. The state therefore "changed" (new reference) on every measurement even when geometry was identical.measuredFallbackRectis a dependency of the second layout effect, which re-dispatchesSYNC_FIT_PANES_EVENT;use-terminal-container-fit-sync.tslistens and runs xtermfit(), which resizes the observed body/parent nodes →ResizeObserverfires again → new object → effect → SYNC_FIT → fit → resize … an unbounded measure↔fit feedback loop that never settles → React #185.The fix
In
updateRect(), compare measuredtop/left/width/heightwith the last committed rectangle and return the previous state reference when every change is under one CSS pixel. This suppresses identical measurements and sub-pixel jitter without rounding away precise geometry. Genuine geometry changes of at least one pixel still commit.Fix evidence — failing → passing repro test
Regression test:
src/renderer/src/components/terminal-pane/TerminalPaneOverlayLayer.react185.test.tsx(@vitest-environment happy-dom). It forces the fallback path (globalThis.__ORCA_WEB_CLIENT__ = true), captures theResizeObservercallback, and verifies three behaviors: 50 identical measurements cause no extra render; 100 alternating sub-pixel measurements across an integer boundary settle without losing precise CSS geometry; and a genuine resize commits exactly once.BEFORE (buggy HEAD — FAILS):
50 identical-geometry ticks → 50 extra commits = the unbounded churn that manifests as React #185 in production.
AFTER (with fix — PASSES):
50 identical-geometry ticks → 0 extra commits (React bails on the unchanged reference).
Also green on the rebased branch: full
src/renderer/src/components/terminal-pane/suite (181 files / 2317 tests),tsc --noEmit -p config/tsconfig.tc.web.json,oxlint, React Doctor lint, and the max-lines ratchet.ELI5
The terminal draws an invisible ruler to measure where it should sit. Every time it measured, it wrote down the size on a fresh sticky note — even when the size hadn't changed. React saw a "new" note and re-did the layout, which nudged the ruler, which triggered another measurement, another note, another layout… forever, until the app fell over. The fix: round the numbers and, if the new note says exactly the same thing as the last one, don't write a new note at all. The loop stops.
Trade-offs / regressions
Adversarial review
2 loops, both CLEAN. Each loop used a fresh sub-agent instructed to refute the fix.
pane-fit.ts(performSafeFitearly-returns when proposed cols/rows match); confirmed no null-branch regression; confirmed theuse-tab-agent.ts:244/:273SortableTab-variant effects are already bounded (generation ref + one-shot early-return), so no hardening was warranted; ran the repro test green. → CLEANstyleuseMemonon-churn, and confirmed the app renders under<StrictMode>with correct observer teardown (no leak/double-seed). Could not construct any still-looping scenario attributable to the fix. → CLEANPerf review (
/perfskill, via sub-agent)Confirmed the fix removes the wasted work (render churn + fit thrash) rather than masking it, adds no new cost, and transitively stops the
styleuseMemoand second-effect churn. One low-severity suggestion (dropisVisiblefrom the first effect's dep array) was considered and declined: the overlay slot stays mounted across worktree switches while the per-group[data-tab-group-body-id]element unmounts/remounts on worktree deactivate/reactivate, and theisVisibledep is what re-runs the effect to re-observe()the new body element. Removing it risks a stale-geometry regression on the exact Windows fallback path this PR fixes — not behavior-preserving, so left as-is.Crash reports
terminal.workbenchf1783c09/5ff8a4e6/52aabedb