Repository navigation
Studio: key the modal pointer-lock rules off attributes that never sit above the thread - #17006
Merged
Merged
Conversation
…t above the thread Radix writes pointer-events: none on <body> for every modal menu and dialog. The rules that depend on it (thread and side pane covers, inert page and lower-layer restorations) were keyed on that inline style, so each open and close made WebKit walk and re-match every element under <body>, the whole thread included: about 45 ms per write at 150 turns, on top of the flat inherited restyle the thread scroller already stops. src/lib/modal-pointer-lock.ts keeps Radix's write and mirrors the lock onto attributes: the thread roots, their ancestors (subject-only rules), every other subtree of the page (descendant rules, as before), and dialogs or menus a stacked layer turned into a lower layer. index.css keys the same four rules on those, so a toggle only reaches the elements they style.
…tsx does The gate's lock check toggles the body lock; without the watcher the modal rules never engaged there, so a costly rule keyed on the new attributes would have gone unseen.
Member
Author
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
iam-knoit
pushed a commit
to SynhalaAI/unsloth
that referenced
this pull request
Nov 9, 2026
…i#17284) ## Problem On macOS WebKit, opening or closing a menu or dialog still cost far more in a long chat than in a short one (Round 11 real runners: composer menu about 200 to 250 ms at 150 turns against 72 to 100 ms at 1 turn; Settings 390 to 560 ms against 232 to 306 ms). unslothai#16902 and unslothai#17006 removed the whole-thread restyles that Radix's body `pointer-events` lock caused in Chromium; WebKit still paid for the scroll lock. ## Cause Every modal open and close sets or clears `body[data-scroll-locked]`, and WebKit re-ran style and layout over the whole page for it: 1. `hub.css` still had `body[data-scroll-locked] .hub-modal-pe-guard`. A body attribute before a descendant combinator makes WebKit re-check every element under `<body>`, every message included. unslothai#17006 removed this pattern from `index.css`, but its test only scanned `index.css`. 2. The lock rule flips `<body>` from `overflow: visible; position: static` to `hidden; relative`, which re-lays out the whole long page in WebKit. WebKit microbenchmark (Playwright WebKit, Mac UA, one lock on and off with a forced style and layout flush, median of 5): 3 ms at 1 turn; 77 to 121 ms at 150 turns on main; 22 to 33 ms with the hub rule removed; 0 ms with the hub rule removed and the body overflow and position preset. ## Change - `hub.css`: the body-keyed rule is removed. Every `.hub-modal-pe-guard` element also carries `pointer-events-auto`, which unslothai#17006's region-keyed rule already sets to `none` behind a modal (and the lower-layer rule covers stacked dialogs). Checked in Chromium and WebKit: the guard reads `auto` at rest, `none` with Settings open and `auto` after close, on main and here alike. - `index.css`: `@media screen { body { overflow: hidden; position: relative; } }`, so the lock changes nothing on `<body>`. Print keeps document flow. Desktop already sets `html.tauri body { overflow: hidden }`. No route scrolls the document itself: on main, every route at 1440x900 and 900x560 has the document's scroll height equal to the viewport (pages scroll their own containers). - `tests/modal-pointer-lock.test.ts` now scans every `src/**/*.css` and fails on `data-scroll-locked`, `aria-hidden` or `data-aria-hidden` before a combinator (it names the hub rule on main). `tests/webkit-modal-page-restyle.test.ts` pins the screen preset. ## Results Real macos-15 Safari WebKit (two runners, main twice as A/A, arms rotated, 3 cycles each), open / close ms at 150 turns, main / main (A/A) / this PR: | Surface | solid | Glass | | --- | --- | --- | | Composer menu open | 228 / 246 / 198 | 314 / 347 / 198 | | Composer menu close | 262 / 304 / 218 | 309 / 314 / 218 | | Command palette close | 315 / 348 / 290 | 382 / 396 / 322 | | Search chats close | 352 / 364 / 318 | 406 / 415 / 333 | | Model picker open | 259 / 310 / 306 | 300 / 330 / 227 | | Settings close | 364 / 414 / 384 | 465 / 455 / 388 | | Settings open | 404 / 436 / 404 | 510 / 618 / 543 | Closes improve on almost every surface beyond the A/A spread, and opens do for the composer menu and, with Glass, the model picker and search. Settings and shortcuts opens stay within noise: their cost is mostly the dialog mount. Long chats still cost more than short ones on macOS WebKit (composer menu about 200 ms against 72 to 100 ms at 1 turn); the remaining growth is not from the attribute toggles measured here. No visible change. Frontend suite 15,326 pass, `tsc` clean, full long-chat gate passes. --------- Co-authored-by: Nilay Yadav <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On long chats in WebKit (the macOS app's WKWebView, Safari), each modal menu or dialog open and close costs a thread-sized style pass. The cause is not where it first looks.
Radix writes
pointer-events: noneon<body>while a modal layer is open.pointer-eventsis inherited, but:where(.aui-thread-viewport) { pointer-events: auto }(#16902) already stops the inheritance at the thread scroller. What still scales with the chat are the four rules that depend on the lock (#16902, #16961), which were keyed on the body's inline style:body[style*="pointer-events: none"] .aui-thread-root::after(thread cover)body[style*="pointer-events: none"] .chat-artifact-pop-surface .side-pane-lock-cover::after(side pane cover)body[style*="pointer-events: none"] :is(.pointer-events-auto, .sidebar-row-action):not(...)(page restorations):is([role="dialog"], ...)[style*="pointer-events: none"] .pointer-events-auto(lower layers)When the
[style*=...]match on an element flips, WebKit walks and re-matches every element under it. On<body>that includes the whole thread. The lower-layer rule triggers the same walk for the body flip, because WebKit only looks at the attribute part of that compound.Forced style + layout flush per write, Playwright WebKit with the macOS UA, 150 turns (55.8k elements, 55.0k of them in the thread), median of 5:
body.style.pointerEvents = "none", as shipped[style*=...]rules deletedpointer-events: noneon the thread scroller's parent, with the rules<html>used as an ancestor in a rule (even[x] .one-element)In real menus at 150 turns the write accounted for 49-96 ms of each open and 48-72 ms of each close (timed between two forced flushes). With the write stubbed out, the longest frame of a menu open dropped from 255-441 ms to 123-200 ms (command palette, search, composer, chat options, Tools). Chromium pays 9-12 ms per write at both lengths, and the long-chat gate's lock check reads 5.3 ms at 40 turns and 20.6 ms at 200 turns on main.
Fix
Radix's write stays as it is, so everything that reads the body lock still sees it:
tooltip-modal-layer.ts, the inheritednone, the Playwright checks. Only the CSS rules move to cheaper keys.src/lib/modal-pointer-lock.ts(installed inmain.tsxnext to the other WebKit guards) watches the body'sstyleattribute. While the lock is up it mirrors it onto attributes that never sit above a thread:data-modal-lock-threadon each.aui-thread-root. Only used on the element it styles (the cover).data-modal-lock-pathon each ancestor of a thread root. Only used on the element it styles.data-modal-lock-regionon every other child of those ancestors. Together these are the rest of the page, split into subtrees that hold no thread. Descendant rules key on this, as they did onbodybefore.data-modal-lock-loweron a dialog, alert dialog, menu or listbox whose inlinepointer-eventsRadix set tononebecause a stacked modal layer opened above it.index.css: the same four rules, keyed on those attributes. Same declarations, same exclusions. A thread root that is not found (say, one mounted inside a region while a modal is open) still gets its cover through[data-modal-lock-region] .aui-thread-root::after.childListobserver on just those elements. Anything mounted deeper lands inside a region (covered by the descendant rules) or inside a thread root (excluded, as before). Lower layers are tracked by astyleattribute observer that only runs while the lock is up, plus a scan of the regions when the lock goes up (for a non-modal menu that turns lower in the same commit). Unlocking clears every mark and disconnects both observers. One watcher per document; installing it again does nothing.Results
Same host, same build pair, servers on one machine. The host was heavily loaded (load average about 130 on 36 cores), so timings are noisy. The model picker does not take the body lock, so it serves as the noise reference: up to about 55 ms there.
Forced flush per body lock write (median of 5-7, 2-4 sessions per arm):
Long-chat gate lock check (Chromium, CDP style recalc per open or close): 5.3 ms at 40 turns and 20.6 ms at 200 turns before, 0.8 ms and 1.0 ms after.
Real menus, 150 turns, base and head interleaved, 3 reps x 3 cycles. Each cell is the longest frame in ms, as a median with the range of per-rep medians in brackets:
The clear wins are the ones above the noise band: Tools menu open (-85 ms), command palette open (-78 ms) and rename close (-76 ms). The rest move by about one write's worth or sit inside the noise. Settings is dominated by other work.
In Chromium, elements restyled per open or close go up by 0-37 (the roughly 32 elements that get an attribute; for example Tools open 630 -> 663, close 479 -> 515). Style ms stays the same or drops (Settings close 33 -> 19 ms, chat options open 34 -> 25 ms).
What remains in WebKit is the inherited write itself: 17-25 ms, flat from 1 to 150 turns, on the roughly 750 elements outside the thread. Removing it would mean replacing Radix's body lock with a blocker element. That changes hit-testing for window chrome that sits at z-40 to z-120 and is meant to stay live (
.modal-pe-live: navbar, titlebar, combobox, toasts), so it is not done here.Behaviour
Behaviour walk at 150 turns, base vs head, in Chromium and in WebKit with the macOS UA. It compares a 792-point
elementFromPointgrid, the computedpointer-eventsof every restoration (.pointer-events-auto,.sidebar-row-action,.modal-pe-live, the thread scroller), the cover pseudo-elements, and the body and layer state, in 14 states: idle; Tools menu; Tools submenu; chat options; Settings; Settings with its select open; Settings after the select; after Settings; browser pane; browser pane under the Tools menu; Library; Library under its Filter menu; Library after. Result: identical in both engines.noneunder a modal andautowithout one..pointer-events-autoelement inside Settings readsnonewhile its select is open (the lower-layer rule) andautootherwise.Tests
tests/modal-pointer-lock.test.ts, which fails on main:[style*=...]selector remains inindex.css;modal-lock-thread-cover.test.tsandwebkit-modal-page-restyle.test.tsnow follow the new selectors.tests/studio/playwright_keyboard_shortcuts.py: 232/232 on base and head (Chromium + WebKit).tests/studio/playwright_find_in_page.py: 452/452 on base and head.tests/studio/playwright_long_thread_gate.py): PASS on head, with and without the watcher on its page.node_modules.node scripts/typecheck.mjs --testsis clean.Not covered