Repository navigation
Studio: stop WebKit restyling the whole page when dialogs, menus and the browser pane open or close - #16961
Merged
Conversation
…the browser pane open or close On a long chat WebKit (the macOS app engine and WebKitGTK) still spent seconds per dialog or menu open and close, and about 24 s opening the browser pane, after #16902. Each cost is a full-page style recalc, about 2 to 2.5 s at 100 turns, that Chromium does not pay: - Radix's scroll lock (react-remove-scroll) adds non-passive wheel, touchmove and touchstart listeners on the document on open and removes them on close. WebKit folds window and document listeners of those types into every element's style (event listener regions), so each add and remove restyles the page. - react-remove-scroll-bar removes its injected <style> on close; removing a stylesheet makes WebKit rebuild every style. - react-resizable-panels adds and removes its document pointer listeners each time a panel group re-registers, which the browser pane does several times while it opens and closes. Pointer listener sets count for WebKit the same way. - A dialog whose exit animation runs with focus still inside it ends in one more full restyle. Fixes, no change to what is shown: - react-remove-scroll is aliased to src/lib/remove-scroll.tsx: the library's own UI half with the same body data-scroll-locked counter, and the styles it injected now static in index.css. Its wheel and touch cancelling is dropped: under a modal layer nothing outside it can be wheel-scrolled (body is pointer-events: none, the thread sits under the #16902 cover, the page never scrolls) and lists inside dialogs already scroll on their own. - One no-op document listener per pointer event type is held for the page's lifetime (src/lib/pointer-listener-pin.ts), so the panel library's adds and removes no longer change the set. - A closing dialog blurs the focused element inside it when its exit animation starts (src/lib/closing-dialog-focus.ts); Radix still returns focus to the trigger on unmount. Tests: tests/webkit-modal-page-restyle.test.ts pins the alias, the lock styles, the pointer pin and the closing-dialog blur.
Codex Review Summary: ❌ FailedThis 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. |
Member
Author
|
@codex review |
…og is open With a modal menu open (no full-screen overlay), wheel over the browser pane still scrolled its file view: the shown side pane sets its own pointer-events: auto, so it never inherited the body lock, and the #16902 cover only spans the thread. react-remove-scroll's document listeners used to cancel that wheel. The same transparent cover now sits over the browser and research panes while the lock is up (both roots are position: relative; portaled menus and dialogs stay above at z-50). It needs its own compositing layer, or Chromium's compositor hit-tests the scroller underneath and scrolls it. No listeners are added per open, so WebKit still restyles nothing page-wide. As over the thread, a click on the pane while a modal menu is open now only dismisses the menu instead of also reaching the pane.
…odal layer With a nested modal menu open (Skills dialog, then Skill actions), wheel over a skill row still scrolled the Skills list behind the menu: the rows restore pointer-events-auto, so they stay hit-testable even though Radix marks the dialog as a lower layer (inline pointer-events: none). react-remove-scroll's document listeners used to cancel that wheel. Under the lock those restorations now resolve to none in two places: - inside a dialog, alert dialog, menu or listbox that Radix has made a lower layer; - in the page (the sidebar inset) while the body lock is up; modal layers portal to <body>, so the top layer is never inside it. The thread's own are left to its cover, so a lock toggle restyles only the few elsewhere. A runtime audit (every hit-testable element inside a scrollable ancestor, with the lock applied) found these plus the API monitor toolbar; with this change it finds none on any route.
…hats Drop the page-wide sidebar-inset pointer-events rule: dialogs portaled into the page (Recipe Studio passes a container) host live comboboxes whose options then could not be clicked. The one page hit from the audit, the API monitor toolbar, gets its own rule. The lower-layer dialog/menu rule now skips popper content wrappers so a popup opened from a lower layer stays interactive. Key the side-pane cover on a static class instead of a :is() / attribute subject. The old subject made Chromium invalidate the whole thread on every body pointer-events toggle (108 ms at 200 turns in the long-chat gate); with the class it is about 10 ms. [skip ci]
The Library's sticky toolbar restores pointer-events over the page scroller, like the API monitor toolbar, so wheel over it scrolled the Library behind an open Filter menu once the document wheel listeners were gone. Give it a static class and add it to the same body-lock rule. [skip ci]
Per-element rules for page restorations under a modal menu did not converge (the API monitor and Library toolbars, then the Downloads card, whose list scrolled 350 px behind an open menu). Replace them with one rule: while the body lock is on, every pointer-events-auto element goes inert except inside the top dialog (contained or portaled), popper popups, the thread (its cover already blocks it) and elements marked modal-pe-live. modal-pe-live marks what is meant to work over a modal: the window titlebar and resize edges, the mac drag regions, the closing screen, the interface zoom popup, toasts and the combobox positioner.
The scroll-lock stand-in is the only importer of react-remove-scroll/UI, so a cold dev server found it after the first scan, re-optimized and reloaded the page. Native Safari did not recover from that reload and the smoke pages stayed blank. Listing it in optimizeDeps.include bundles it up front. [skip ci]
An open media disclosure arrow restores pointer-events in CSS (.sidebar-row-action.is-disclosure-open) rather than with the pointer-events-auto class, so wheel over it scrolled the sidebar behind an open chat context menu. Include .sidebar-row-action in the body-lock rule.
This was referenced Nov 7, 2026
Merged
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Nov 7, 2026
…t above the thread (unslothai#17006) ## 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: none` on `<body>` while a modal layer is open. `pointer-events` is inherited, but `:where(.aui-thread-viewport) { pointer-events: auto }` (unslothai#16902) already stops the inheritance at the thread scroller. What still scales with the chat are the four rules that depend on the lock (unslothai#16902, unslothai#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: | Side effect | 1 turn | 150 turns | |---|---|---| | `body.style.pointerEvents = "none"`, as shipped | 24-28 ms | 59-107 ms | | Same, with the four `[style*=...]` rules deleted | 19-23 ms | 17-25 ms | | Inline `pointer-events: none` on the thread scroller's parent, with the rules | 1 ms | 34-47 ms | | Same, rules deleted | 1 ms | 0 ms | | Any attribute on `<html>` used as an ancestor in a rule (even `[x] .one-element`) | 1-5 ms | 27-46 ms | | The same attribute used only on the element it styles | 0 ms | 0-1 ms | 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 inherited `none`, the Playwright checks. Only the CSS rules move to cheaper keys. - `src/lib/modal-pointer-lock.ts` (installed in `main.tsx` next to the other WebKit guards) watches the body's `style` attribute. While the lock is up it mirrors it onto attributes that never sit above a thread: - `data-modal-lock-thread` on each `.aui-thread-root`. Only used on the element it styles (the cover). - `data-modal-lock-path` on each ancestor of a thread root. Only used on the element it styles. - `data-modal-lock-region` on 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 on `body` before. - `data-modal-lock-lower` on a dialog, alert dialog, menu or listbox whose inline `pointer-events` Radix set to `none` because 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`. - While locked, children added to a thread root's ancestors are picked up by a `childList` observer 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 a `style` attribute 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. - The long-chat gate page installs the watcher too, so its lock check times the rules the app actually uses. ## 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): | | WebKit 1 turn | WebKit 150 turns | Chromium 1 turn | Chromium 150 turns | |---|---|---|---|---| | Before | 23-28 ms | 59-107 ms | 9-12 ms | 9 ms | | After (includes the marks) | 25-37 ms | 28-48 ms | 12 ms | 10-12 ms | 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: | Surface | WebKit before | WebKit after | Chromium before | Chromium after | |---|---|---|---|---| | Tools menu open | 321 [320-371] | 236 [203-290] | 67 | 50 | | Tools menu close | 159 [146-173] | 120 [114-147] | 50 | 33 | | Command palette open | 404 [257-476] | 326 [269-344] | 167 | 150 | | Command palette close | 221 [208-225] | 198 [198-291] | 117 | 117 | | Search chats open | 446 [379-492] | 394 [358-413] | 150 | 150 | | Chat options open | 340 [319-361] | 293 [285-312] | 83 | 83 | | Chat options close | 177 [141-234] | 164 [159-173] | 50 | 33 | | Rename chat open | 261 [230-290] | 222 [194-236] | 84 | 117 | | Rename chat close | 260 [240-382] | 184 [152-210] | 83 | 83 | | Composer menu open | 329 [327-460] | 379 [235-406] | 100 | 100 | | Composer menu close | 153 [131-160] | 133 [126-134] | 50 | 50 | | Settings open | 518 [482-522] | 513 [509-557] | 233 | 233 | | Settings close | 200 [189-201] | 197 [175-202] | 167 | 133 | | Model picker open (no body lock) | 397 [392-400] | 341 [329-401] | 117 | 117 | 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 `elementFromPoint` grid, the computed `pointer-events` of 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. - An outside click on another chat's sidebar row closes the menu and does not navigate. - Wheel over the thread or the sidebar under the Tools menu, and over the thread under Settings, moves them 0 px in Chromium. With no modal open it scrolls normally. - Sidebar row actions and the Library toolbar restoration are `none` under a modal and `auto` without one. - The browser pane under a menu hits its cover. - The submenu item and the select option are hit. - The Settings tab under its open select is not hit. - A `.pointer-events-auto` element inside Settings reads `none` while its select is open (the lower-layer rule) and `auto` otherwise. - No marks are left after any close. ## Tests - New `tests/modal-pointer-lock.test.ts`, which fails on main: - no `[style*=...]` selector remains in `index.css`; - the thread and path attributes are only ever used on the element they style; - with a fake DOM, the lock splits the page so that every element outside the thread roots is in exactly one region or on the path, and no message is marked; - children mounted next to the thread while the lock is up join a region; - stacked layers are marked lower and lifted again, including a layer that was already lower when the lock went up; - unlocking clears everything and leaves only the body observer; - a second install is a no-op. - `modal-lock-thread-cover.test.ts` and `webkit-modal-page-restyle.test.ts` now 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. - Long-chat gate (`tests/studio/playwright_long_thread_gate.py`): PASS on head, with and without the watcher on its page. - Full frontend suite: 15,121 pass. The one failure is the KaTeX stylesheet Vite test, which also fails on main with a symlinked `node_modules`. `node scripts/typecheck.mjs --tests` is clean. ## Not covered - Real Safari and WKWebView on macOS. All WebKit numbers come from Playwright WebKit (WebKitGTK) with the macOS UA. Windows WebView2 was not run. - Wheel under a modal in local WebKit is not decisive. After any wheel, with or without a modal, the 150-turn thread jumps by 24-27k px in both arms, so that check only shows the two arms agree. - The Skills list under its actions menu (the case the lower-layer rule was written for) was not driven in the app, because this test home lists no skills. It is covered by the synthetic restoration inside Settings under its select, and by the unit test. - There was no A/A timing run on this loaded host. The model picker, which takes no body lock, is the noise reference instead. - Touch devices (iPad Safari).
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, and the Linux app's WebKitGTK), closing any dialog or menu took 5 to 7 seconds, and on Linux WebKit the browser pane took over 20 seconds to open. Chromium (Windows) was not affected.
WebKit restyles every element on the page when certain document-level listeners or stylesheets change:
wheelortouch*listener on documentpointermove/pointerleavelistener on document<style>data-scroll-locked,pointer-events,aria-hidden, focus restoreThree things hit those paths:
react-remove-scroll) adds non-passive wheel and touch listeners on the document when a dialog or modal menu opens and removes them on close, andreact-remove-scroll-barremoves its injected stylesheet on close.react-resizable-panelsremoves and re-adds its document pointer listeners each time the chat's panel group re-registers, which is what the browser pane triggers (3 passes on open, 2 on close, with or without any CSS).Fix
src/lib/remove-scroll.tsx, aliased forreact-remove-scrollinvite.config.ts: the same component and the samedata-scroll-lockedcounter on<body>, but no document listeners; the styles the library injected live permanently inindex.css. Under a modal layer nothing outside it can be wheel-scrolled anyway (body ispointer-events: noneand the thread sits under the Studio: stop dialogs and menus from restyling the whole chat on open and close #16902 cover), and lists inside dialogs scroll on their own.src/lib/pointer-listener-pin.ts: one passive no-op document listener per pointer event type registered at startup, so the panel library's add and remove no longer change the set of listener types WebKit tracks.index.css: the transparent cover Studio: stop dialogs and menus from restyling the whole chat on open and close #16902 puts over the thread while a modal is open now also covers the side pane (browser, research). The pane sets its ownpointer-events: autoonce shown, so without the library's document listeners its file view would scroll under a modal menu; the cover blocks it without a per-open listener.index.css: elements that restore their own pointer events stay inert under a modal layer, so a wheel over them cannot scroll what sits behind it. Two class-keyed rules, CSS only:modal-pe-live).vite.config.ts:react-remove-scroll/UIis pre-bundled for the dev server. It is only imported by the stand-in, so a cold dev server found it late and reloaded the page, which native Safari did not recover from.src/lib/closing-dialog-focus.ts: when a dialog starts its exit animation with focus inside it, the focused element is blurred; Radix still returns focus to the trigger afterwards.Results
Real macOS (GitHub
macos-15, real WebKit, 150 turns, 2 reps, all arms on one runner), time to close:Opening was already fast on real macOS and stays so. On Linux WebKit (Colab, 100 turns, 3 reps) the browser pane opens in 1.9 s instead of 22.4 s and closes in 0.9 s instead of 11.1 s; Settings open/close goes from 6.6 / 7.1 s to 1.2 / 1.1 s. Chromium is unchanged or 10 to 40 ms faster.
Behaviour is the same in both engines: wheel over the browser pane under the Tools menu moves it 0 px (it scrolls normally with no menu open); the lock attribute is set and the body has
overflow: hiddenandpointer-events: nonewhile a dialog or menu is open; wheel over the thread under Settings or the tools menu moves it 0 px while the Settings pane itself still scrolls; focus lands on the same element after close. Screenshots of 10 surfaces, open and after close, show no visible change (pixel differences at 100 turns match a base-vs-base run).Tests
studio/frontend/tests/webkit-modal-page-restyle.test.ts: the alias, the static lock styles, the pointer listener pin and the closing-dialog blur.node_modules.node scripts/typecheck.mjs --testsis clean.One deliberate change: clicking the side pane, or a page control that restores its own pointer events (Downloads button, banners), while a modal menu is open now only closes the menu, as clicking the thread already did. Wheel over the Skills list, the Library toolbar, the Downloads card or the sidebar under a modal menu moves them 0 px (they scroll normally otherwise). Recipe Studio comboboxes inside its dialogs stay usable.
Not covered: touch devices such as iPad Safari (the lock's touch cancelling is dropped), and users with reduced motion, for whom the closing-dialog blur does not run.