Skip to content

Studio: stop menus, sidebar and browser pane from restyling the whole chat - #16938

Merged
danielhanchen merged 3 commits into
mainfrom
studio-has-subject-rewrite
Nov 6, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-has-subject-rewrite

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

On a long chat, toggling the sidebar, opening run settings, the model picker, chat options or the browser pane each restyled the whole thread, about 9,200 to 18,400 elements at 150 turns, on every engine (Chromium / Edge for Windows, WebKit for macOS and Linux). Typing in WebKit paid a similar cost on every keystroke.

The cause is CSS rules where the styled element comes after a :has(), for example X:has(...) Y or X:has(...) > Y (139 such rules in the built CSS: wallpaper and glass rules, Tailwind group-has-* variants, hub README badge rows, menu rows). When anything under X changes, the browser re-checks every element that could match Y, and their right-hand parts (a, img, [data-slot], [data-state], :focus-visible) match every source chip, favicon, tool card and reasoning row in the thread. Deleting just these rules took a sidebar toggle from 9,216 to 141 elements restyled; no single rule was responsible (14 each caused it alone).

Fix

82 of the 139 rules are rewritten so :has() is in the subject or replaced by a flag; the look is unchanged.

  • Wallpaper and glass rules (about 60, index.css): read flags on the host element (data-wallpaper-ready, -outline-off, -flat, -frame-flat, -image, -preview-outline-off). chat-background/host-flags.ts mirrors them from the wallpaper layer before paint, using exactly the old :has() argument for each flag, and only writes on a change. Flags are repeated in the selectors so specificity is unchanged.
  • Windows page blur radius: reads data-sidebar-frame, set in __root.tsx from the sidebar's own condition.
  • Hub README badge rows: hub/lib/badge-rows.ts marks them with data-badge-row.
  • RAG embedding menu row: the item checks its own later siblings for the pin, so it is the subject.
  • Sidebar row actions (12 group-has-*): [&:has(~.sidebar-row-action...)], since the actions are always the row's last siblings.
  • Info hint: marks itself data-near-focus when its row has keyboard focus.
  • Queue editor hint, library card time, RAG pin, project chat date: the group sets a custom property in its own has-[...] class and the child reads it.
  • Four selector strings in has-anchor-order.test.ts were being picked up by Tailwind and shipped as real rules; they are now spelled so the scan skips them.

The remaining 57 rules (shadcn primitives, chat model notice, files panel, sidebar nav hover, composer pills, toasts, sidebar footer fade) are left as they are and listed in an allowlist; keep-only bisects show none of them costs anything on a sidebar toggle or on WebKit typing.

Results

150 turns, base vs this PR side by side, 3 reps (restyle counts identical across reps):

Chromium Elements restyled Style time
Sidebar toggle open / close 9,216 -> 135 / 9,270 -> 188 111 -> 3.6 ms / 114 -> 4.5 ms
Run settings open / close 9,363 -> 258 / 18,397 -> 256 112 -> 10 ms / 202 -> 6.8 ms
Model picker open / close 10,493 -> 1,464 / 9,423 -> 390 123 -> 18 ms / 110 -> 6.6 ms
Chat options close 9,498 -> 463 132 -> 25 ms
Browser pane open / close 9,581 -> 583 / 18,242 -> 146 130 -> 24 ms / 221 -> 11 ms
Settings open (dialog mount) 2,115 -> 2,111 48 -> 45 ms

WebKit typing at 150 turns: p50 61 -> 25 ms per key, p95 66 -> 33 ms (:focus-visible and [data-state] inside these rules were re-checked across the document on every keystroke). Chromium typing is unchanged.

Look: every element's computed style (including ::before / ::after) and a pixel diff, base vs this PR, on a solid thread (tool cards, reasoning rows, source chips, favicons), sidebar row hover, an open row menu, keyboard focus on a row's pin, and solid and Liquid Glass 3D over a wallpaper (thread, welcome page, Appearance). Computed styles are identical apart from the per-session wallpaper blob URL and the random welcome greeting; pixel diffs are 0 outside the greeting.

Guard

  • tests/has-subject-after.test.ts (about 1 s) compiles index.css with the build's Tailwind plus every has class in the scanned sources and fails on any new rule of this shape outside the allowlist, on stale allowlist entries, and on @custom-variant definitions that contain :has(.
  • tests/has-host-flags.test.ts checks the new flags and markers are wired up.

Tests

Full frontend suite passes except the KaTeX stylesheet test that also fails on main in a local setup with a symlinked node_modules; node scripts/typecheck.mjs --tests is clean. Existing tests that matched the old selector text are updated.

…p restyling the thread

Rules shaped X:has(A) Y put Y on Chromium's shared :has() invalidation set: any DOM change under
an X it had tested (the workspace, the chat column, any p/div above an image) re-checked every
Y-like element below it, so a sidebar toggle, run settings, the model picker, chat options or the
browser pane restyled 9-18k thread elements at 150 turns. WebKit re-checks the whole document
when something named inside such a :has() changes, so :focus-visible and [data-state] in them cost
every keystroke.

- Wallpaper and glass rules read host flags (data-wallpaper-ready, -outline-off, -flat,
  -frame-flat, -image, -preview-outline-off) that the wallpaper layer mirrors onto its parent
  before paint (chat-background/host-flags.ts); each flag is repeated to keep the old specificity.
- The Windows page blur reads data-sidebar-frame from the root instead of a :has() over the sidebar.
- Hub README badge rows are marked data-badge-row by a ref callback (hub/lib/badge-rows.ts).
- The RAG menu row item lights itself with :has(~ [data-row-action]...).
- Sidebar row parts use [&:has(~.sidebar-row-action...)] instead of group-has-*; the queue editor
  hint, library card time, RAG pin and project chat date read a custom property set by the
  group's own has-[...]; info hints mark themselves data-near-focus.
- tests/has-subject-after.test.ts compiles index.css with Tailwind plus every has- class token in
  the files Tailwind scans and fails on any new style-after-:has() rule outside a measured
  allowlist; has-anchor-order.test.ts spells its fixtures so they no longer ship as app CSS.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-06T18:30:19.017366Z
We couldn’t complete this review. Comment @codex review to try again.
3837369 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@danielhanchen
danielhanchen merged commit 42489f2 into main Nov 6, 2026
@danielhanchen
danielhanchen deleted the studio-has-subject-rewrite branch November 6, 2026 22:27
imaderaya pushed a commit to pub-forks/unsloth that referenced this pull request Nov 7, 2026
…unslothai#16978)

Follow-up to unslothai#16931. The long-chat gate carried allowances for costs
main had when it landed. unslothai#16938 (the `:has()` rewrite), unslothai#16942 and
unslothai#16957 removed most of those costs, so this lowers the allowances to
today's readings so they cannot creep back.

## Changes

- `tests/studio/has_subject_allowlist.txt`: regenerated. 57 selectors
are still allowed, 61 are gone. Lint on main: 197 `:has()` rules, 57
non-subject, 0 new, 0 stale.
- `tests/studio/_area_matrix.py`:
- All 9 per-area element-count ceilings are removed, so those areas get
the normal 2x growth check. unslothai#16938 fixed every one of them; none
restyles the whole thread on open any more.
- Glass ceilings lowered to about 1.2-1.3x the highest reading on
current main.
- A recheck page that fails to load or measure now keeps the first
verdict instead of crashing the gate with a traceback. A recheck can
only lower a reading, so this never hides a failure.

## Count ceilings removed (elements restyled at 200 turns)

| Area | Old ceiling | Now | 200 vs 40 turns |
|---|---|---|---|
| model_picker | 44000 | 459 | 0.99x |
| chat_options | 17000 | 2091 | 1.45x |
| browser_pane | 45000 | 1259 | up to 2.55x |
| account_menu | 30000 | 346 | 1.0x |
| organize_chats | 30000 | 226 | 1.0x |
| chat_row_menu | 32000 | 1817 | 1.55x |
| sidebar_sections | 45000 | 163 | up to 1.18x |
| sidebar_toggle | 30000 | 365 | 1.06x |
| run_settings | 45000 | 1214 | 2.13x |

browser_pane and run_settings grow a little faster than 2x but stay
under the 3000-element floor (about 4 elements per turn, not a
whole-thread restyle).

## Glass ceilings (ratio vs the default look)

Highest reading over 3 runs pinned to 4 CPUs and 7 runs on a loaded
36-core host.

| Mode | Old | Highest | New |
|---|---|---|---|
| frosted, other areas | 10 | 5.79 | 7 |
| blurred, other areas | 10 | 5.50 | 7 |
| liquid, other areas | 10 | 5.65 | 7 |
| liquid-3d, other areas | 12 | 5.41 | 7 |
| frosted, Settings scroll | 28 | 9.69 | 12 |
| blurred, Settings scroll | 28 | 12.18 | 15 |
| liquid, Settings scroll | 28 | 10.08 | 13 |
| liquid-3d, Settings scroll | 28 | 9.60 | 12 |

## Testing

- Full gate on main: PASS 4 times (270-310 s).
- Still fails when it should:
- a planted subject-after-`:has()` rule is reported by name ("57
allowlisted, 1 new");
- a synthetic Glass material with a 40px backdrop blur fails 8 cells at
4.0-15.7x, with no real mode failing.
- `test_area_matrix.py`, `test_has_lint.py`, `test_css_culprit.py`: 58
passed.
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