Skip to content

fix(renderer): stop the modal toast rule from freezing large diffs - #23721

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/toast-modal-selector-freeze
Sep 29, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/toast-modal-selector-freeze

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

What it fixes and where

With a large diff open in Source Control (for example a Staged Changes view of several big files), a burst of file changes on disk, such as a rebase, a branch switch or a formatter run, could freeze the Orca window until it was killed. The regression came from #22423, which added a style rule that lifts error toasts above an open dialog or sheet backdrop.

Scope: the desktop renderer only, on every platform (it is plain CSS that Chromium evaluates the same way on macOS, Linux and Windows). Nothing changes for SSH, mobile, the wire protocol or stored data. What users see stays the same: toasts still appear above dialog and sheet backdrops, and still sit below menus, popovers and selects when no dialog is open.

ELI5

A style rule asked the browser "is there a dialog backdrop anywhere on the page?", and the browser re-asked that question by scanning the whole page after every tiny change inside the diff editors. Now the page body answers it once, only when a backdrop is added or removed, and the toast reads the answer.

What Changed

Before, #22423's rule was body:has([data-slot='dialog-overlay'], [data-slot='sheet-overlay']) [data-sonner-toaster] { z-index: 60 !important }. Opening a Staged Changes diff of several large files and then changing those files on disk froze the window.

Now body sets a variable when a dialog or sheet backdrop is one of its direct children, and the toaster reads it: body:has(> [data-slot='dialog-overlay'], > [data-slot='sheet-overlay']) { --toaster-z-index: 60 } and [data-sonner-toaster] { z-index: var(--toaster-z-index, 40) !important }. The same diff stays responsive through the same burst.

Mechanism

When a :has() on an ancestor is part of the toaster's own selector, Chromium has to re-check that :has() and look for toasters across the page after DOM changes that might affect it. Monaco's diff editors change the DOM constantly, so every style update paid for a walk of the whole document, and the renderer never caught up.

Only narrowing the old rule to body:has(> …) [data-sonner-toaster] (this PR's first commit) was not enough. It fixed the reported freeze, but it still paid a page-wide walk whenever an element was added near body, for example each tooltip or menu mounting (about 9 ms per mount on a page of 150k elements, against 0.04 ms with no rule), and that cost grew with page size.

With the :has() alone on body, Chromium only re-checks body, and the answer only changes when one of body's direct children is a backdrop that is added or removed. Unrelated DOM changes then cost the same as with no rule at all, at every page size we measured. The cost moves to opening and closing a dialog, where the inherited variable restyles the page once; the dialog library already restyles the page at that moment (it sets pointer-events: none on body for modal dialogs), so a full open-and-close cycle costs about the same with or without this rule.

Why

Dialog and sheet backdrops are portaled straight into document.body: the dialog portal renders each child, including the backdrop element itself, directly into the default container (body), nothing wraps it, and neither our DialogContent nor our SheetContent passes a custom container. So "direct child of body" selects exactly the backdrops #22423 targeted, and the rule still keys off the real modal backdrops rather than scroll-lock state (which menus and selects also set), with no new state.

Alternatives considered. Keeping the :has() inside the toaster's selector with only the > added: still a page-wide walk near body. An attribute set on body from the dialog and sheet components: a second record of "a modal is open" that has to be kept in step with the real backdrops, which #22423 deliberately avoided. A fixed toast layer above modal backdrops (no conditional rule at all): the simplest shape, but it would also lift toasts above non-modal floating surfaces such as the floating terminal (layers 45 to 50), which is a product decision outside this fix. Reverting #22423: brings back the unreadable error behind the Add Project dialog.

Linked Issue

No issue. Found from the scheduled E2E run on main, where combined-diff-invalidation-freeze-repro.spec.ts ("a rebase-style burst of external file changes keeps the diff responsive and loaded") timed out on every run since 2026-09-26. Bisected with targeted E2E runs of only that spec: it passes before #22423 (run 36494532122), fails at #22423 (36494538490), and passes on main with just that rule removed (36494544695).

Visual Proof

Live hidden Electron builds on a Mac (production renderer, isolated profile), comparing main with this PR. The toast CSS at head 6f1e9c7eb12 is identical to the c076c6a2b1f build shown here (the last commit only changes a test).

Error toast above the Add Project dialog backdrop, dark and light (toast layer 60, backdrop 50):

Toast above the Add Project dialog backdrop, dark

Toast above the Add Project dialog backdrop, light

After the dialog closes, the same toast drops back to layer 40:

Toast back at layer 40 after the dialog closes

No dialog open: the Resource Manager popover (60) and the Keep-awake menu (70) still cover the toast (40):

Resource Manager popover above the toast

Keep-awake menu above the toast

The 8-file × 15,000-line Staged Changes diff after three rounds of real on-disk rewrites, loaded and responsive on this PR:

Large staged diff after a burst of file changes, this PR

Responsiveness during that burst (360 timer ticks expected in the window; three runs per build):

main this PR
95th-percentile input delay 9.1 s / 17.2 s / 14.9 s 5 ms / 33 ms / 2 ms
timer ticks that fired 11 / 2 / 15 341 / 280 / 355

Swapping only the toast rule inside a running page confirms the rule alone causes it: main with the old rule rewritten to the child-only form stays healthy, and this PR's first commit with its rule rewritten back to the old form freezes like main.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

native-chat-stop-layering.test.ts now pins the shape of the rule: toasts default to 40 through the variable, the lift is exactly the child-only rule on body, and a :has() placed in the toaster's own selector fails the test. That is a cheap guard that runs on every PR, because E2E does not gate merges and this regression kept main's freeze spec red for two days. Checked in vitest: passes on this branch, fails with #22423's rule and with the > removed.

Targeted E2E on c076c6a2b1f (same CSS as the head): the freeze spec passed twice (runs 36499928046 and 36499933417; worst 95th-percentile lag during the burst 0.2 ms), and add-project-error-toast-stacking.spec.ts, #22423's regression test, passed in dark and light (run 36499928046).

Headless Chrome benchmark of the rule shapes on a Monaco-sized page, style-recalc time for unrelated DOM churn: #22423's rule was many times slower than no rule and grew with page size, the child-only form was cheap for deep edits but still paid a page-wide walk for elements added near body, and the variable form matched no rule in every case measured.

Live QA (above) on macOS: toast above dialog in both themes, back to 40 on close, below popovers and menus with no dialog, a popover opened inside a dialog still above the lifted toast, and the freeze comparison with main. A toast above a sheet backdrop could not be shown live, because every sheet with a backdrop needs a connected Linear or Jira account or an agent artifact; a backdrop element added directly under body lifts the toast to 60, and one nested inside the app root does not. Popout windows load the same CSS but have no toaster, so the rule has nothing to do there.

Review

Two things to check. First, the assumption that dialog and sheet backdrops are direct children of body (see Why). If that ever stops holding, the failure is harmless and visible: the toast drops back behind the backdrop, as before #22423, and never a freeze. Second, the trade-off: opening or closing a dialog or sheet now restyles the page once, in exchange for removing a cost that was paid on every DOM update and grew with page size.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Not changed here, and true before this PR: the command palette's backdrop has no data-slot, so toasts stay below it; and a toast at the bottom right is partly covered by the floating terminal when no dialog is open.

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)

The rule that lifts toasts above a dialog or sheet backdrop matched
body:has(<overlay> anywhere). Chromium re-evaluates a descendant :has()
on body for DOM changes anywhere in the page, so with large Monaco diffs
open every editor mutation re-scanned the document and the renderer
stopped responding.

Dialog and sheet overlays portal straight into body, so matching them as
direct children keeps the same behaviour while only changes to body's own
children can affect the rule.
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Low risk] Adjusts modal and toast layering in styles.

The PR appears safe to merge based on the reviewed changes.

Summary

The PR narrows the modal-overlay selector to direct children of body to avoid rescanning large diffs, and updates the regression test to require those child combinators. The previous test-coverage finding is fixed.

Reviews (3) · Last reviewed commit: "test(renderer): fail the toaster layerin..."

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

A single CSS selector change in the renderer, narrowing the modal toast rule added in #22423 to keep error toasts above dialog/sheet backdrops.

  • Child-combinator :has() — body:has([data-slot='dialog-overlay'], [data-slot='sheet-overlay']) [data-sonner-toaster] became body:has(> [data-slot='dialog-overlay'], > [data-slot='sheet-overlay']) [data-sonner-toaster], so the invalidation set is body's own children rather than the whole subtree.
  • Comment update documenting the direct-child assumption that makes the narrowing safe.

I verified the load-bearing assumption against the installed Radix source rather than taking it on faith: DialogPortal wraps each child in PortalPrimitive asChild container (node_modules/@radix-ui/react-dialog/dist/index.mjs:87), the custom DialogPortal/SheetPortal never pass a custom container, and no call site uses DialogOverlay/SheetOverlay outside DialogContent/SheetContent. So the overlays are direct children of body and the > narrows the match to exactly the same elements. DialogPortal also drops data-slot="dialog-portal" instead of forwarding it, so overlays retain their own data-slot.

The existing regression spec tests/e2e/add-project-error-toast-stacking.spec.ts already pins this behavior for real: it asserts the toaster's computed z-index exceeds the open overlay's (40 vs 50 if the new selector stopped matching), in both themes. No new test needed.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4ceb6849-180a-436a-9b5d-1471dc4aa75e

📥 Commits

Reviewing files that changed from the base of the PR and between c076c6a and 6f1e9c7.

📒 Files selected for processing (1)
  • src/renderer/src/components/native-chat/native-chat-stop-layering.test.ts

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


📝 Walkthrough

Walkthrough

The toaster z-index uses the --toaster-z-index variable, with a default value of 40. When a dialog or sheet overlay is a direct child of the body, the variable is set to 60. The test checks the variable fallback and verifies that toaster selectors do not contain :has().

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 6f1e9

The toaster retains its default stacking level and rises above open dialog or sheet overlays. No actionable merge-blocking risk is identified.

Architecture Summary

Architecture risk: 🔵 Low · up to 6f1e9

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/renderer/src/assets/main.css: The toaster’s z-index is now controlled by --toaster-z-index, defaulting to 40. The modal rule no longer targets the toaster or assigns its z-index directly; instead, when a dialog or sheet overlay is a direct child of body, it sets the variable to 60.
  • observed — Modified behavior in src/renderer/src/components/native-chat/native-chat-stop-layering.test.ts: The test replaces its fixed toaster z-index: 40 expectation with a variable defaulting to 40. It adds checks for setting that variable to 60 when body has a direct dialog or sheet overlay child, and for the absence of :has() in toaster selectors.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
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 identifies the renderer fix for the modal toast rule and its impact on large diffs.
Description check ✅ Passed The description is complete and detailed. It explains the user impact, technical change, rationale, alternatives, testing, visual proof, review points, and checklist status. It does not link an issue,…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

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.

…endant :has()

The child-combinator form still ran a whole-page walk after unrelated DOM
changes (about 3x cheaper than the original, but still proportional to page
size). Setting a custom property from a :has() on body alone takes the rule
off that path; only opening or closing a backdrop restyles.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

Since the prior Pullfrog review, the freeze fix was reworked from a child-combinator selector on the toaster to an inherited custom property set by a :has() whose subject is body alone, plus a test update.

  • Body-variable mechanism — body:has(> [data-slot='dialog-overlay'], > [data-slot='sheet-overlay']) now only sets --toaster-z-index: 60, and [data-sonner-toaster] reads z-index: var(--toaster-z-index, 40) !important. The overlay-dependent :has() no longer appears in the toaster's selector, so unrelated subtree mutations stop re-evaluating it.
  • Layering test update — the existing native-chat-stop-layering.test.ts now pins the var(--toaster-z-index, 40) declaration and asserts no :has(...) [data-sonner-toaster] selector returns.

I confirmed the variable resolves correctly: the toaster is a descendant of body (sonner renders inline, no createPortal, inside App.tsx's root <div>), no @property or other rule sets --toaster-z-index, and the overlay direct-child assumption is unchanged from the earlier-reviewed commit. So the computed z-index is 60 while a backdrop is open and 40 otherwise — identical to the prior form — and add-project-error-toast-stacking.spec.ts's contract still holds.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…ator is dropped

The guard only rejected a :has() inside the toaster's selector. Dropping the `>`
from the body :has() (or removing the lift rule) still passed, and the unscoped
form re-runs on every data-slot element change anywhere in the page, the same
freeze the PR fixes. Assert the exact child-only rule shape.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

Since the prior pullfrog review, the only new commit (6f1e9c7) tightens the regression guard for the freeze fix; the production selector and variable mechanism are unchanged.

  • Layering guard now pins the body rule — native-chat-stop-layering.test.ts gained a positive assertion requiring body:has(> [data-slot='dialog-overlay'], > [data-slot='sheet-overlay']) { --toaster-z-index: 60; }, so dropping the child combinators (reintroducing a descendant :has() on body) fails the test rather than staying green.
  • Toaster assertion updated — the existing check now expects z-index: var(--toaster-z-index, 40) !important, matching the c076c6a mechanism.

I verified the new guard can actually fail: removing the > combinators from main.css fails at native-chat-stop-layering.test.ts:23, and with the file restored the full test file passes 3/3. This closes greptile's P2 on the same test.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready on substance; CI blocked by main (not this PR)

Verdict: the fix is correct, fixes the freeze, and keeps #22423's toast behaviour. Three review passes ran; the third came back clean. Not merged and not marked ready: CI on the head is red because of a break on main, not this change (details below).

What changed during review (head 6f1e9c7eb12):

  • c076c6a2b1f: the first commit's body:has(> …) [data-sonner-toaster] fixed the reported freeze but still made Chromium walk the whole page when elements were added near body (each tooltip or menu mounting cost about 9 ms on a 150k-element page, and grew with page size). The :has() now sits on body alone and sets --toaster-z-index: 60; the toaster uses z-index: var(--toaster-z-index, 40) !important. Unrelated DOM changes now cost the same as having no rule. Opening or closing a dialog restyles the page once, which the dialog library already does at that moment, so a full dialog cycle costs about the same as before.
  • 6f1e9c7eb12: the unit guard in native-chat-stop-layering.test.ts now pins the child-only rule and rejects a :has() in the toaster's own selector. Checked in vitest: it passes on this branch and fails with fix(toast): keep folder errors above standard modal backdrops #22423's rule and with the > removed. This matters because E2E does not gate merges.

Automated evidence: targeted E2E on c076c6a2b1f (the head has the same CSS) passed the freeze spec twice (runs 36499928046, 36499933417) and add-project-error-toast-stacking.spec.ts in dark and light (36499928046). Formatter and lint are clean on both changed files.

Live QA (hidden Electron builds on a Mac, main vs this PR):

  • Error toast above the Add Project dialog backdrop in dark and light (toast 60, backdrop 50), and back to 40 when the dialog closes: pass.
  • No dialog open: popovers (60) and menus (70) still cover the toast (40): pass. A popover opened inside a dialog stays above the lifted toast: pass.
  • Freeze: an 8-file × 15,000-line Staged Changes diff with three rounds of real on-disk rewrites. On main the 95th-percentile input delay was 9 to 17 s and only 2 to 15 of 360 timer ticks fired. On this PR it was 2 to 33 ms, with 280 to 355 ticks. Swapping only the toast rule inside a running page reproduces and removes the freeze, so the rule alone is the cause.
  • Toast above a sheet backdrop: not shown live, because every sheet with a backdrop needs a connected Linear or Jira account or an agent artifact. A backdrop element added directly under body lifts the toast to 60; one nested in the app root does not. Popout windows have no toaster, so the rule has nothing to do there.

Toast above the Add Project dialog backdrop, dark

Toast above the Add Project dialog backdrop, light

Resource Manager popover above the toast with no dialog open

Large staged diff after the burst, responsive on this PR

CI: red on 6f1e9c7eb12 (typecheck, static analysis, verify, persistence), so test and e2e were skipped. The cause is on main: src/main/codex/codex-background-task-frames.ts imports ./codex-structured-journal-provider-verdicts, a file main no longer has (TS2307). #23783 is open to fix main's typecheck. Once main is green, re-run this PR's checks and confirm test passes. The earlier head (c076c6a2b1f, same CSS) was fully green.

Not caused by this PR, worth their own follow-ups:

  • Adding a project path that does not exist offers "Open as Folder" and then adds a broken folder project with no error toast (reproduced on main).
  • The command palette's backdrop has no data-slot, so toasts stay below it (true since fix(toast): keep folder errors above standard modal backdrops #22423).
  • With no dialog open, the floating terminal (layers 45 to 50) partly covers a bottom-right toast (40).
  • rich-markdown-editor.css:37 uses a descendant :has() before the element it styles, over the markdown editor; same bug class on a smaller subtree, not measured.

Open design question for a maintainer: a fixed toast layer above modal backdrops and below menus would remove the conditional rule entirely, but it would also lift toasts above the floating terminal. That is a product decision, so it is left out of this fix.

@brennanb2025
brennanb2025 merged commit f4829f0 into main Sep 29, 2026
23 of 32 checks passed
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
…3745, #23783, #22971, #22565, #22846, #23724, #23721, #23693, #23810) into #23059

#23671 (group chat rows by the turn that produced them) is ported onto
#23059's turn-scope model, so there is one grouping mechanism, not two:

- A host that states each row's turn scope groups by that scope, as
  before. #23671's journal-order derivation (rows between one turn record
  and the next belong to it) moves from the timing selector into
  src/shared/native-chat-turn-grouping.ts and runs only for a host that
  states no scope, replacing the positional fallback there.
- #23671's anchor rules live in structuredAgentTurnAnchors, which
  membership, settled timing and the live clock all read: a turn whose
  opener key nothing resolves yet takes the send still in flight ahead of
  its record (Codex before its echo), else its own record.
- The live turn is one key again. #23671 made row liveness follow the
  owning turn, so the bar key and the liveness key are always the same;
  nativeChatTurnMembership now returns only liveTurnKey (barTurnKey,
  activeTurnOpenedBy and turnKeysByItemId are gone).
- A turn with no user bubble draws its bar above its first row
  (nativeChatTurnBarRows, desktop and mobile), and a turn's diff rollup
  goes under its last row.
- The Codex full-history restore writes each record ahead of its items;
  that also fixes the derived turn scope on #23059's journal.

#23026 (Stop from the moment a message is sent) is ported onto #23059's
command turns: the cancel paths ask the translator for a command's
provider turn instead of the removed compaction tracker, and a Stop that
names no turn still ends a running /compact through its child.
performCancel moved to structured-agent-session-turns-cancel.ts to keep
the turns module under the line limit.

#22090's awaitingInput replaces showTurnStatus/showLiveTurnActivity; the
waiting-behind-/compact rows are kept.
naufaldi added a commit to naufaldi/orca that referenced this pull request Oct 28, 2026
… Mermaid renders

Opening a Markdown preview with many Mermaid diagrams froze scrolling for
tens of seconds. Mermaid measures each label with getBBox /
getComputedTextLength / getTotalLength, and every call forces a style
recalc. Three rules made each of those recalcs cover the whole document:

- body:has(> overlay) .app-layout > :not(.window-controls) (modal blur)
- group-has-[:focus-visible]/row (SshTargetCard)
- group-has-[:focus-visible]/reasoning (NativeChatReasoningDisclosure)

Each one alone was enough. The blur now flows through a body custom
property set by a subject-only body:has(), the same shape stablyai#23721 used
for the toaster z-index. The two Tailwind utilities use the scoped
[[class~='group/x']:has(:focus-visible)_&] form from stablyai#23725.

On the issue's 19-diagram repro (dev build), all diagrams render in
4.2 s instead of 47.5 s, style recalc during open drops from ~35 s to
0.36 s, and scrolling while diagrams render goes from about 1 fps to a
16.7 ms median frame.

Refs stablyai#34312

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant