Skip to content

fix(terminal): stop measure<->fit feedback loop in overlay fallback (React #185) - #10026

Merged
nwparker merged 2 commits into
mainfrom
OrcaWin/terminal-workbench-react185
Jul 23, 2026
Merged

nwparker merged 2 commits into
mainfrom
OrcaWin/terminal-workbench-react185

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

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 full anchor-size() support, shouldUseCssAnchorPositioning() returns false, 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 ResizeObserver whose callback updateRect() called setMeasuredFallbackRect({ 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. measuredFallbackRect is a dependency of the second layout effect, which re-dispatches SYNC_FIT_PANES_EVENT; use-terminal-container-fit-sync.ts listens and runs xterm fit(), which resizes the observed body/parent nodes → ResizeObserver fires again → new object → effect → SYNC_FIT → fit → resize … an unbounded measure↔fit feedback loop that never settles → React #185.

The fix

In updateRect(), compare measured top/left/width/height with 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 the ResizeObserver callback, 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):

 ❯ TerminalPaneOverlayLayer.react185.test.tsx (1 test | 1 failed)
   × does not re-render on ResizeObserver ticks with an unchanged rect
AssertionError: expected 50 to be less than or equal to 1
   expect(extraRenders).toBeLessThanOrEqual(1)
 Test Files  1 failed (1)
      Tests  1 failed (1)

50 identical-geometry ticks → 50 extra commits = the unbounded churn that manifests as React #185 in production.

AFTER (with fix — PASSES):

 Test Files  1 passed (1)
      Tests  1 passed (1)

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

  • Sub-pixel changes are coalesced until cumulative movement reaches one CSS pixel. The committed rectangle retains its precise measured values, and one-pixel-or-larger geometry changes still update normally.
  • No behavior change on macOS (CSS-anchor path — the fallback effect early-returns and this code never executes) or for real resizes/tab switches (those still commit).

Adversarial review

2 loops, both CLEAN. Each loop used a fresh sub-agent instructed to refute the fix.

  • Loop 1: verified the loop is closed at the source and independently found the pre-existing secondary guard in pane-fit.ts (performSafeFit early-returns when proposed cols/rows match); confirmed no null-branch regression; confirmed the use-tab-agent.ts:244/:273 SortableTab-variant effects are already bounded (generation ref + one-shot early-return), so no hardening was warranted; ran the repro test green. → CLEAN
  • Loop 2 (different angles): checked stale-closure / React 19 StrictMode double-invoke of the functional updater (pure → safe), effect-dep interleaving, null↔rect oscillation, style useMemo non-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. → CLEAN

Perf review (/perf skill, 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 style useMemo and second-effect churn. One low-severity suggestion (drop isVisible from 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 the isVisible dep 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

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated TerminalOverlaySlot to be exported and changed fallback measurement updates to ignore insignificant geometry changes. Added a jsdom/Vitest regression test that mocks dependencies and ResizeObserver, simulates stable, sub-pixel, and genuine geometry changes, and verifies render counts and overlay styles.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is thorough but does not follow the required template and omits several required sections. Reformat the PR body to match the template: add Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the terminal overlay fallback feedback-loop fix and the React #185 crash.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

OrcaWin and others added 2 commits July 22, 2026 18:10
…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).
@nwparker
nwparker force-pushed the OrcaWin/terminal-workbench-react185 branch from e1b264c to dfc4b1d Compare July 23, 2026 01:12

@nwparker nwparker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nwparker
nwparker merged commit 3b86405 into main Jul 23, 2026
2 of 3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.
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