Repository navigation
Studio: take the three live sidebar menus off the body modal layer - #9229
danielhanchen wants to merge 1 commit into
Conversation
UI evidence: the menus are identical, and the one thing that changed is behind themTwo isolated installs, This is a performance change, so three of the four shots are an IDENTITY assertion. They hold,
Menu geometry and contents agree exactly on both sides: 1. sidebar per-thread "Chat options" -- byte-identical2. the same menu, still open, with a real wheel gesture over the threadThis is the behaviour change named in the PR body, and it is the only visible one. BEFORE the 3. sidebar list-header "Organize chats" -- 2 pixels of antialiasing4. project page per-chat "Chat options" -- byte-identicalThe facts that did moveRead off the same servers that were photographed: That A note on the run itself, since it matters for reading the numbers above. The driver exits |
Correction: my earlier UI evidence comment described the wheel gesture wronglyIn the UI evidence comment above What the image actually showsMeasuring the two underlying shots of shot 2 ( Zero. The entire left 402 px of the frame -- the whole sidebar, the trigger, and the open menu Why, and why it was predictableThe sidebar is its own scroll container. A wheel gesture over the thread pane scrolls the What actually happens, measuredRather than replace one unmeasured sentence with another, I instrumented both scroll containers
So the real difference is that the thread scrolls behind the open menu where before it was That last fact is what makes this benign rather than a detached-popover bug: the menu is One thing this could NOT test, stated rather than glossed: the sidebar itself does not overflow A note on the first version of the probe, because it is the same trap in a different costume. Where each half of this correction comes fromWorth separating, because the two halves rest on different evidence:
What this does and does not changeNothing about the performance result or the functional matrix depends on this: it was a |
|
Closing this. Measured at 100K against a concurrent in-band null control and every metric landed inside the run's own floor. It also stacks on #9051, which conflicts with main and has no prepared rebase, so what was actually measured here was the 9051 plus 9229 stack rather than this change alone. Neither half showed anything. Closing both. |




Follow-up to #9051, and the fix for #9168.
#9051 takes the chat menus off the body modal layer and measures a large win, but it does not
reach the sidebar. The three menus a user actually opens were still modal, and one of them is
the most expensive menu measured anywhere in this work: on one packaged production build,
same 220-message thread, same run, the action-bar More menu patched by #9051 opens and closes
in 38.6 ms and the sidebar's "Chat options" menu, identical interaction, in 382.6 ms.
This converts the three, with the guard, and measures each one.
The change
Three
<DropdownMenu>roots getmodal={false}, and each one mounts<MenuDismissGuard />first in its content:
app-sidebar.tsxrenderSidebarHeaderMenuapp-sidebar.tsxper-thread triggerchat-page.tsxproject page rowSix lines of source, plus
studio/frontend/tests/sidebar-menu-modality.test.ts.This PR is stacked on #9051 and targets its branch. The guard lives in
src/lib/menu-dismiss.tsandsrc/lib/menu-dismiss-guard.tsx, which exist only there, and itis mounted PER MENU rather than globally, so
modal={false}on its own is not the wholechange for these three. Merge #9051 first; GitHub will retarget this to main.
Why the modal layer costs anything
A modal Radix layer parks
pointer-events: noneon<body>for as long as it is open(
@radix-ui/react-dismissable-layer).pointer-eventsis INHERITED, so that single writeinvalidates computed style for the entire mounted subtree, which on a chat page is the thread.
The cost of opening a menu therefore scales with the thread rather than with the menu.
modal={false}is the upstream answer to exactly this (radix-ui/primitives discussions #2873and #1720, shadcn-ui/ui #6908).
Read directly off the page, while each menu is open, on all three menus and all three engines:
document.body.style.pointerEventsnone""pointer-eventson bodynoneautodata-scroll-lockedon bodyaria-hiddenbody childrenMeasurement
Every number in this section is off a PRODUCTION bundle. There is no vite dev server
anywhere in this PR's timings. Both arms are
vite buildoutput with distinctassets/index-*.jshashes, served as static dists. That is worth stating outright, because adev server does not merely scale timings: React's development-only paths cost in proportion to
elements created per frame, so the bias is correlated with a treatment that changes how much
subtree work is mounted, and it does not cancel in a base/head ratio. Taking menus off the
Radix modal layer is exactly such a treatment, so a dev-server measurement here would not have
been salvageable by ratioing.
Two Studios on ONE backend, differing only in the frontend bundle they serve
(
unsloth studio --frontend <dist>), one dist built from #9051's head and one from thisbranch. Each side has its own
UNSLOTH_STUDIO_HOMEand its own port, and each was checked tobe serving its own
assets/index-*.jsbefore anything was timed. Identical seeded content onboth: a project, a 220-message plain thread and a 220-message markdown thread (187,118 chars).
One shared backend is deliberate: the diff is three frontend files, so holding the backend
fixed removes it as a variable rather than duplicating it.
One press to open, Escape to close, timed from before the press to after the last
[role=menu]has gone. Each trial times BOTH sides back to back and the arm order alternates by trial, so
the second half is the reversed-order repeat and a drift on this shared box cannot favour
either arm. The paired ratio is the result; absolute milliseconds are context. A trial is
rejected outright unless both arms mounted the same amount of the page, since the cost being
removed scales with the mounted subtree.
Medians of 3 paired trials:
Repeated on a plain-text thread of the same 220 messages, which mounts 2,343 nodes rather than
12,024, every cell still improves and every cell improves by less: chromium -25.6% / -28.0% /
-16.8%, firefox -59.0% / -47.4% / -25.6%, webkit -63.7% / -64.2% / -36.4%. That is the point.
The head arm is flat at about 170 ms across both thread weights on all three engines; only
the base arm grows. 18 cells, all 18 faster, and the per-trial ratios inside each cell agree
to within a few points.
The project page number is small on purpose and should not be read as a disappointment: that
route has no thread mounted, so there is little style to invalidate. It is the same defect,
costing less, and it costs nothing to remove.
What was checked, per menu
Full matrix, three engines, three arms (base, this branch, and a guardless mutant), three
repeats per case, driven with
page.mouseandpage.touchscreenso every press is a real hittest that honours
pointer-events.Two runs were thrown away rather than reconciled.
Five unrelated static servers on this box were killed at 21:27 UTC, and the firefox matrix was
mid-run on its head arm at that moment, so it was discarded and re-run clean. The re-run
reproduces the discarded one cell for cell, across all 3 arms x 3 menus x 25 checks, so
the contamination in fact changed nothing; it was discarded and re-run anyway rather than
reconciled after the fact. The chromium cells were re-run for a different and better reason:
they were written at 20:49:12 by a
menu3_matrix.pythat was edited at 20:55:54, so thosenumbers came from a harness version that no longer exists, and nothing in the results
themselves would have revealed it.
No timing trial was affected either way. Every number in the Measurement section was
written between 20:04 and 20:17 UTC, over an hour before the kill, and those three Studios
stayed up throughout with unbroken request logs across 21:27.
On this branch, on all three menus:
click and nothing became click-blocked
"Chat options" menus; on the list-header menu the press does not dismiss at all, see below
everywhere except one cell, called out below
Touch was run on all three engines, not just chromium and webkit: Playwright's
hasTouchdispatches real touch events on firefox as well, and these are real firefox measurements.
Where this evidence is weaker than the table above looks
Three things cut against the result and are stated here rather than left in a footnote,
because each one would otherwise quietly inflate it.
1. The kill control kills on two of the three menus, not three. On the list-header
"Organize chats" menu, the guardless mutant scores 3/3 on
held_dismiss_did_not_navigate,quick_dismiss_did_not_navigateanddismiss_then_space_did_not_navigate-- the same ashead. It is not that the guard is doing its job there; it is that the harness's press never
dismisses that menu on any tree, so there is no swallowed click for the guard to be credited
with. A kill control that does not kill on a third of the surface is a weaker control than it
first appears, and the list-header menu's protection rests on the other checks
(
underlying_swallowed,neutral_click_after,touch_underlying_swallowed, the double-clickcounter) rather than on these three.
2. The base arm's
underlying_swallowedis not measured against the same element as head's,and cannot be. On base,
body { pointer-events: none }makesdocument.elementFromPointreturn the root, so the probe attaches its click counter to
<html>; on head and the mutant itattaches to a
<div>. So "0/3 on base" means<html>received the click, not that the controlunderneath fired. The head-vs-mutant comparison is unaffected -- both are the same
<div>--and that is the comparison the kill control actually rests on, but the base-vs-head contrast is
softer than the bare numbers suggest.
This has a consequence worth stating in plain terms rather than leaving as a 3/3.
underlying_swallowed3/3 together withneutral_click_after3/3 means: with a menu open, auser who clicks a control must press it twice to activate it. The first press dismisses the
menu and is eaten by the guard; the second press works normally. That is the guard's deliberate
design, inherited from #9051, and it is not new here. But whether it is an improvement on what
the modal layer did cannot be settled from these numbers, because the base column is the
confounded
<html>measurement above and so the two are not comparable. It is reported as adescribed behaviour, not as a pass.
3. One touch row is chromium-only and was previously written as if it held everywhere. See
below.
4. Only 28 of the 77 checks in the matrix can be shown to measure anything. Four separate
instrument defects were found while preparing this PR, and every one produced plausible-looking
numbers:
the numbers came from a version that no longer exists;
dialog" on the arm that definitely has a modal layer;
room_up170,256,room_down0), so a scroll-locked arm and an out-of-room arm both reported 0 px moved;press is always consumed, so the button it pressed never activated and it measured the
swallow rather than the dialog.
None is visible by reading the code and none looks wrong in the output. All four were caught
by the same signature: a check that read identically where it should have differed, or a bare
zero that could not distinguish absence from unreachability. That is the thing to look for
when touching this harness.
So the same standard this PR applies to its assertions (a mutant must kill each one) is applied
to the probes themselves.
scripts/menu3_discrimination.pysweeps every check and asks what itreads on an arm where the behaviour is present against one where it is absent:
The 49 split into two honest groups. Most are regression guards that cannot discriminate by
construction, because no arm lacks the behaviour they test:
mouse_open,item_count,dismiss_closes,select_reached_item,select_took_effect, all threekeyboard_*,touch_open,dblclick_outside_closes. They are legitimate as "nothing broke" statements andthey are reported as exactly that -- not as evidence the change works, and with their own
instruments unvalidated, since nothing in this experiment makes them fail. The rest are the
cases named above where the interaction never fires on any tree (the list-header menu's
held, quick and dismiss-then-Space presses; chromium's
touch_dismiss_closeson the sidebar"Chat options" menu), and those are stated as non-discriminating rather than as passes.
The general principle behind the scroll fix is worth stating because it applies to all of them:
a probe must be able to distinguish "the thing did not happen" from "I could not make the
thing happen". A bare 0 cannot.
Four rows are reported as they were observed rather than as passes:
touch_dismiss_closeson the sidebar "Chat options" menu comes back 0/3 on base, head andthe mutant alike on chromium only. On firefox and webkit that same cell is 3/3 on all
three trees. A tap on the neutral spot does not close that one menu on chromium on any tree,
so it is pre-existing and not a regression, but it is not a pass either.
because the row the harness presses is not adjacent enough to that menu to close it. The
same is true of the quick-press and dismiss-then-Space cases on that menu: it is not that
the guard holds there, it is that the press never dismissed that menu to begin with.
On base,
body { pointer-events: none }makeselementFromPointreturn the root, so thebase arm's click counter is attached to
<html>while head's and the mutant's are attachedto a
<div>. Sounderlying_swallowed0/3 on base means "<html>received the click", not"the control underneath fired". The head-vs-mutant comparison is unaffected, since both are
the same
<div>, and that is the comparison the kill control rests on.later rows in that column are absent. Head reopens it 10/10. I have not established whether
that is a real base-tree defect or a harness artefact, and I am not claiming it as a fix.
The behaviour changes, stated rather than left to be discovered
The bar for this PR is identical-except-for-performance. It does not fully meet that bar, so
the differences are listed here with their measurements rather than left to be found.
1. The thread scrolls behind an open menu, where before it was locked
Going non-modal drops the
react-remove-scrollscroll lock along with the pointer-eventswrite. Measured, one of these menus open, a real wheel gesture over the thread:
scrollTopdelta[0, 0][0, 0]The menu does not close and it does not move. That second half is what makes this benign
rather than a detached-popover bug: the menu is anchored to a trigger that lives in the
sidebar, and the sidebar is a separate scroll container from the thread, so scrolling the
thread cannot move the trigger the menu is attached to. Escape still closes it and scrolling
back restores the view.
An earlier version of this section, and a since-corrected comment below, said the scroll
carries the menu off screen with its trigger. That was wrong, and the evidence image
refutes it: 0 differing pixels for x < 402, so the sidebar and the open menu are
byte-identical between the two sides.
The wheel-over-the-SIDEBAR case is unmeasurable in this fixture: the sidebar does not
overflow (
scrollHeight753 againstclientHeight753, identical), so there is nothing toscroll. It is not claimed either way.
app-sidebar.tsxalready ships amodal={false}menu with this behaviour, so it is theexisting precedent rather than a new shape.
2. Focus is not returned to the trigger when an outside PRESS dismisses the menu
Escape is unaffected and is the path that matters most for keyboard and screen-reader users:
focus_return_escapeis 3/3 on base, this branch and the mutant, all three menus, all threeengines. Focus returns to the trigger button with its accessible name.
Dismissing with an outside press is different:
BUTTONBODYTEXTAREA(it navigated)focus_detachedandfocus_in_menu_subtreeare both false, so it is a clean drop to<body>,not focus stranded on an unmounted node.
This is inherited from the guard, not introduced here. The control settles it exactly as it
did for the double click: the sidebar's overflow "More" menu is ALREADY
modal={false}with thesame guard on the base tree, untouched by this PR, and it drops focus to
<body>on base,on all three engines. So the behaviour belongs to the non-modal-plus-guard pattern and this PR
extends it to three more menus. Filed as #9245.
The mechanism, from a focus timeline sampled at every event of the gesture:
Two things combine. The press focuses the row (on base it cannot, because
pointer-events: nonesends the press toHTML), so Radix sees focus already outside the menuand declines to restore it. Then
releaseFocusTakenByTheSwallowedPressinmenu-dismiss.tscalls
active.blur()to kill the pending Space activation, and nothing puts focus back.That blur is deliberate and load-bearing: it is what makes
dismiss_then_space_did_not_navigatepass, one of the checks proven to discriminate. So the fix is not to remove it but to redirect
it, focusing the trigger instead of blurring to nothing, which removes the pending activation
and restores the recovery point in one move.
The comment in
menu-dismiss.tsthat chose blur over restore says "measured on the pre-PRshape,
document.activeElementstaysBODYthroughout" and "Body is where the modal shapeleft focus anyway". The timeline above shows why that is half right: on base focus IS
BODYthrough pointerdown, click and +50 ms, and then Radix's restore lands and it ends on the
trigger. The observation was taken at the wrong instant, and the end state is the opposite.
3. The shared guard's double-click over-swallow
One defect in the shared guard comes with it, and it is not mine to claim as new. A fast
double click outside an open menu loses its second click: the guard swallows both. Measured
10 times per arm, the three converted menus deliver 0 of 2 on this branch. The control settles
it: the sidebar's overflow "More" menu is ALREADY
modal={false}with the same guard on thebase tree, untouched by this PR, and it delivers 0 of 2 on base as well, 10 times out of 10.
The guardless mutant delivers 2 of 2. So the over-swallow belongs to
menu-dismiss.tsandpredates these three menus; this PR extends the guard's reach and the behaviour travels with
it. Worth fixing in the guard, not here.
4. A control must be pressed twice to activate it while a menu is open
underlying_swallowed3/3 withneutral_click_after3/3 means the first press outside an openmenu is consumed and the second lands. That is the guard's deliberate design, inherited from
#9051. As noted above, it cannot be compared against base from this data, because the base
column is the confounded
<html>measurement. It is described, not scored.A modal dialog still shields these menus
The risk that justifies all of the above: Radix's modal layer is what normally guarantees
overlay stacking, so taking three menus off it could let them punch through a modal dialog. It
does not. A genuinely modal dialog (
open={creatingProject}, confirmedgetComputedStyle(document.body).pointerEvents === "none"on every arm, including this branch)was opened with no menu open, and the menu trigger was then pressed.
menu_blocked_by_modal_dialog, 3/3 in every cell, identical on chromium, firefox and webkit:base equals this branch on both converted menus, so there is no regression, and the dialog
keeps its own shield on this branch (
dialog_is_modal,dialog_has_focus,dialog_escape_closesandbody_restored_after_closeall true everywhere).The control is the reason to believe the check rather than the number it produced: it reports
"not blocked" while the converted menus report "blocked", in the same run, so the check is
demonstrably able to move rather than stuck on one value.
Two things this does NOT establish.
dialog_still_open_afteris false in every cell, so thetrigger press also dismisses the dialog, and what is measured is strictly that a press at the
trigger's location does not produce a menu while a modal dialog is up. Whether that is because
the dialog refuses the press or because the hover-revealed trigger is simply unreachable under
pointer-events: noneis unestablished; the verdict survives because base behavesidentically, but the mechanism does not follow from this data.
That control result is itself a pre-existing defect on
main, filed as #9244. It is not causedby this PR, it reproduces identically on base, and it is deliberately not fixed here.
The general lesson from the evidence in this PR
Stated once rather than repeated as three separate caveats: a check can support a comparison
between arms while being unable to support a claim about why either arm behaves as it does.
Most of the results above are of the first kind. Where a mechanism is asserted, it is because
something independent establishes it; where it is not, that is said.
The eleven-menu count, and the file to leave alone
features/chat/thread-sidebar.tsxhas ZERO importers. Nothing undersrc/ortests/references it and vite tree-shakes it out, so the two menus #9051 converts there never mount;
that is why its headline count of eleven is eight live menus. This PR does not touch it, and
the new test pins that fact with an importer sweep, so if it ever gains an importer the test
says so instead of the menus quietly joining the matrix unmeasured.
Tests
studio/frontend/tests/sidebar-menu-modality.test.ts, four tests: each of the three menus ispinned non-modal AND guarded, and the two pinned files are required to have live importers
while
thread-sidebar.tsxis required not to.Every assertion was shown to fail on a deliberately broken tree, individually: ten
mutations, each turning exactly one test red, with the tree checksummed between them and
green again at the end. Six flip one half of one site (modal back on, or the guard removed);
one gives
thread-sidebar.tsxan importer; one pins a file that has none; one makes thesource walk reach nothing; one points a marker at a menu that does not exist.
The runtime assertions were shown to kill something too. A third Studio serves a mutant build
that is this branch with
modal={false}kept and<MenuDismissGuard />removed.underlying_swallowedis 3/3 on head and 0/3 on the mutant on all three menus and allthree engines, and
touch_underlying_swallowedlikewise on firefox and webkit. Thedouble-click counter inverts just as cleanly: head delivers 0 of 2 ten times out of ten, the
mutant 2 of 2 ten times out of ten, on every menu and every engine.
held_dismiss_did_not_navigate,quick_dismiss_did_not_navigateanddismiss_then_space_did_not_navigateare 3/3 on head and 0/3 on the mutant on the two "Chatoptions" menus -- the dismissing press navigates away. On the list-header menu those three
are 3/3 on the mutant as well, so they are not a kill there; as noted above, the harness's
press never dismisses that menu on any tree, so there is no swallowed click for the guard to
be credited with. The list-header menu's kill rests on
underlying_swallowed,neutral_click_after,touch_underlying_swallowedand the double-click counter instead.One cell does not kill and is reported rather than dropped:
touch_underlying_swallowedonthe sidebar "Chat options" menu is 3/3 on the mutant on chromium, where the tap does not
close that menu at all, so it never reaches the element being counted. It kills normally on
firefox and webkit.
Gates
npm run typecheck(tsc -bplustsconfig.test.json) andnpm run buildboth pass.npm testis 3799/3800; the one failure isqueued-model-capabilities.test.ts, the inheritedERR_MODULE_NOT_FOUNDthat #9220 fixes, and it fails identically on the base worktree.npx eslinton the two changed source files reports 19 problems (9 errors, 10 warnings) onthis branch and the identical 19 on base, differing only by a two-line offset that matches
the two lines this PR adds to
chat-page.tsx. All of them are pre-existingreact-hooks/set-state-in-effectandexhaustive-depsfindings in code this PR does nottouch. The new test file lints clean.
Note
npm run typecheckistsc -b.tsc --noEmit -p tsconfig.jsonchecks nothing here,because that config is references-only.
CI
The four red checks on this PR are main-side and are not from this change.
(Python 3.13),Frontend build + bundle sanity,Frontend unit tests (Windows)andRepo tests (CPU)failidentically on every open PR against this base, including ones that touch no frontend code at
all. They are fixed by #9220, which is green at 38/0. The other 28 checks pass here. Please do
not read this PR as red.
Fixes #9168.