Repository navigation
feat(core): one shared dismissal stack for every overlay layer - #4881
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
de1bb14 to
f7582a1
Compare
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsDialog (@astryxdesign/core) · View in Storybook
HoverCard (@astryxdesign/core) · View in Storybook
Layer (@astryxdesign/core) · View in Storybook
Lightbox (@astryxdesign/core) · View in Storybook
MobileNav (@astryxdesign/core) · View in Storybook
Popover (@astryxdesign/core) · View in Storybook
Tooltip (@astryxdesign/core) · View in Storybook
InfoTip (@astryxdesign/lab) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
f7582a1 to
8e73dd0
Compare
8e73dd0 to
bffd3e6
Compare
Every overlay owned its own Escape listener, so one press could dismiss two layers — a popover and the Dialog hosting it, or a modal and the modal it was opened from. Patching that per primitive had already produced parallel registries (the focus-trap Escape stack, Drawer's LIFO registry, useScrollLock's counter). This is the single registry those collapse into, per the plan in #3343. - `useLayerDismissal` registers a layer while it is active; `layerStack` owns ONE document listener and routes each press to the top-most layer. Layers no longer listen, so there is no stopPropagation choreography between element- and document-level handlers to keep in sync. - One press dismisses exactly one layer, with no per-component exceptions. `escapeBehavior` is `close` (default) or `block` — a `required` Dialog swallows the press without closing, so nothing behind it dismisses either. - Top-most is resolved from React-tree nesting via `LayerDepthProvider`, which survives portals and is fixed during render, so an inner and outer layer that mount in the same commit order correctly. DOM containment remains a tie-break for bare focus traps, which render nothing and so cannot provide depth. Nothing is mounted at the app root: the context defaults to 0 and each layer provides depth for its own content. - Presence is asked at press time, not inferred from registration. Hover layers register for their lifetime because their open state lags the DOM by a frame, and answer presence from the DOM instead — so an idle tooltip in the tree never claims an Escape. - The stack calls preventDefault on presses it handles, suppressing the browser's own close-watcher so native and JS cannot both act. One code path covers modal `<dialog>`, non-modal `show()`, `popover="auto"` and `popover="manual"` alike. Fixes two live bugs: a Tooltip inside a Dialog closed the Dialog instead of the tip, and useHoverCard's trigger listener called stopPropagation on ANY Escape while merely focused, silently eating presses meant for a host Dialog. Verified in Chromium against four new stories — modal-in-modal, popover-in-modal, hover-tip-in-modal (both showing and idle), and required-blocks-Escape — plus 15 unit tests, typecheck, eslint and check:repo.
…tory `caption` is not a built-in `TextType` — it only appears as an example of a theme-augmented custom type in the CustomTextTypes JSDoc — so the storybook typecheck failed the build-storybook job. `supporting` is the built-in that carries the intended meaning: 12px (--text-supporting-size) and secondary color by default, i.e. the system's de-emphasized note under a line of body text.
bffd3e6 to
b51650a
Compare
|
Thanks for taking this on — one Escape owner for the whole app is the right direction, and the depth-aware stack is a real improvement over every layer racing the same keypress. The thing I'd want to sort out first: we preventDefault every Escape we handle (
Sizing: this is a lot at once. The stack + Dialog + One sequencing note: #5018 is smaller, non-draft, and on a different channel (pointer, not keydown) — no conflict between the two heads. Worth landing that first and rebasing this on top. What do you think? [Reviewed by Robohands and Cindy] |
`handleCancel` became a bare `preventDefault()` when Dialog moved onto the shared dismissal stack, so a dismissal the browser starts on its own — the Android back gesture, the platform close watcher — stopped closing a modal at all. Escape presses the stack owns never reach `cancel` (the stack preventDefault()s those), so this path only ever sees the dismissals the stack did not route, and dropping it silently lost them. The cancel handler now answers with the stack's own ordering: still always `preventDefault()`, so the browser cannot close a controlled `<dialog>` behind React's back, but dismiss when this dialog is `isTopmost()` and Escape-dismissible. Approach carried from #4865, adapted from its `useEscapeStack` to `layerStack`/`useLayerDismissal`. Also carries #4865's Dialog-level modal-in-modal Escape test — the only real `Dialog` mount guarding nested dismissal in either PR; the stack's own tests are all synthetic layers. It fails against the pre-stack Dialog handler (outer closes too) and passes here, alongside two `cancel` tests, top-most and not. Co-authored-by: Freddy Kusnadi Tan <[email protected]>
All three conflicts are the same one: #4907 moved the IME composition guard to `utils/ime` while this branch was removing the call sites that used it. - `Dialog` and `useTooltip`: main added `isImeKeyEvent(...)` inside the per-component Escape listeners this branch deletes. The guard is not lost — `layerStack` runs the same check once, before it routes a press to any layer, so every layer on the stack is covered by one call. - `useFocusTrap`: kept this branch's `hasOpenLayer()` body and main's import path. Also drops this branch's `hooks/isImeKeyEvent.ts`, a duplicate of the predicate main now owns in `utils/ime`; `layerStack` imports from there. The `hooks` barrel keeps re-exporting it from its new home, so the public surface is unchanged. `useLayerDismissal`'s doc no longer claims the stack orders "whatever mix of layers is open": Lightbox, MobileNav and InfoTip do not register with it yet, and the doc now says so.
The stack claims a press with preventDefault() but leaves propagation alone on purpose, so a keydown listener on window sees an Escape that a focus- trapped layer used to stop. Measured: none on main, one here, with defaultPrevented already true. Anyone listening at that level needs to know.
'Make first required' sat in the first modal, which is inert once the second is open -- so the story could not be driven the way its own copy reads. Moved into the second modal. Driven in Chromium: flip while both are open, one Escape closes the second (the re-registered first does not overtake it), a second Escape leaves the required first standing.
9035e8f to
2af3315
Compare
seq's docblock said 'monotonic open order'. True for a layer that registers when it opens; a hover layer registers at mount and answers isPresent, so for two of those it is mount order. Measured: with a focus-shown tip and a hover-shown tip both up, one Escape takes the earlier-mounted one. Strictly better than main, which took both -- the comment overstated, the code did not. The sheet story's copy told the reader our migration plan. The caller-facing fact stays, the roadmap goes; Scope / follow-ups already carries it.
… places Two comments still called it 'open order' after the field's own docblock stopped. Also names the consequence the ordering rule has and the field's docblock does not: a layer keeps its place for as long as its identity lives, so one that closes and reopens does not move to the top.
The code keys order to the layer's identity; 'fixed when it opens' is true for the re-registration case the sentence is about but not in general, and the body's Known edges already carries the precise version.
A window keydown listener now sees an Escape that a focus-trapped layer used to stop, and the change adds useLayerDismissal and escapeBehavior as public surface. [fix] was the one category it could not be.
A controlled Tooltip or HoverCard used to opt out of the dismissal stack entirely, so its Escape fell through and closed the Dialog underneath. It now stays registered, takes the press when it is top-most, and answers by calling onOpenChange(false) rather than hiding itself — whether it closes is the caller's update to make, exactly as for a controlled Dialog. A controlled close now restores focus to the trigger when the card held it; without that the consumer's own state flip stranded focus on <body>.
The eight add/add conflicts resolved to main's files in the merge; this ports back only the assertions main does not cover and that still hold today (render gates and sizing, layer groups and masks, style restore, registry glyph, xstyle forwarding, context guards). Duplicates of main's coverage are dropped rather than kept twice. Four files went stale over the 815-commit gap and follow today's behavior: the hidden data-table fallback (meta#4382) means chart label and tooltip queries scope to the svg; useTooltip's touch guard is per pointer type (meta#5248) and a controlled tooltip reports Escape through onHide (meta#4881); TableHeaderCell dividers are logical inline-end properties (meta#4434).
…sted viz packages and hooks (#4295) (#4377) * test: cover the viz packages and five core hooks packages/charts and packages/vega had no functional tests at all, and packages/lab's chart primitives (Chart*, Radial*, ThreeD*, Sankey*, SVGIcon) rendered nothing under test. Add colocated tests for each, plus renderHook tests for the three useCalendar* hooks, useCollapsible and useTableFilterState. Harness: charts and vega were falling through to the `node` vitest project, which has no jsdom, no StyleX transform and no jest-dom, so their tests could never have run there. Move both into the `ui` project and give vega the test scripts the other packages already have. 53 test files, 307 tests. Verified: full suite 7943 pass / 430 files, still green with packages/core/dist absent (the cold-CI path, which charts needs because it imports core by bare name for values); 8 sampled mutations across all four packages, each killed by exactly the new test. Refs #4295 * test: cover remaining core hooks and components Finishes the functional-coverage sweep started in 64d9ea3. Adds renderHook tests for useScrollLock, useLightbox, useChatPasteAsToken, useImperativeAlertDialog, useTranslator and useTooltip, plus colocated tests for the components that had none: CommandPaletteEmpty, InputClearButton, TypeaheadItem, ChatSendButton, PowerSearchToken, PowerSearchFilterEditor and TableHeaderCell. Two of the issue's nine "zero-test" components already had tests (ChatComposerDrawer, MobileNavToggle, from #3996 and #3721), so the inventory is smaller than the issue states. Extracts the StyleX declaration read-back helper that three of these files each needed into __tests__/stylexDeclarations.ts rather than landing a third copy. Two branches are deliberately left uncovered, with the reason recorded next to them: the ignored-onOpenChange(true) guards in useLightbox and useImperativeAlertDialog are unreachable through the public surface, and reaching into element props to force them both breaks the repo's no-react-introspection lint rule and asserts a value that is already settled. useTooltip's focus paths are also omitted -- jsdom resolves :focus-visible as :focus, so those tests would pass with the gate deleted. Verified: 8101 tests / 443 files green, eslint and prettier clean, core typecheck clean; three sampled mutations (the send-button variant ternary, CommandPaletteEmpty's xstyle merge, useTooltip's touch suppression) each killed by exactly one new test. Refs #4295 * test: port the branch's remaining assertions onto main's test files The eight add/add conflicts resolved to main's files in the merge; this ports back only the assertions main does not cover and that still hold today (render gates and sizing, layer groups and masks, style restore, registry glyph, xstyle forwarding, context guards). Duplicates of main's coverage are dropped rather than kept twice. Four files went stale over the 815-commit gap and follow today's behavior: the hidden data-table fallback (#4382) means chart label and tooltip queries scope to the svg; useTooltip's touch guard is per pointer type (#5248) and a controlled tooltip reports Escape through onHide (#4881); TableHeaderCell dividers are logical inline-end properties (#4434). * test(calendar): assert month labels as English literals CI's lint job fails on the one raw Intl call left in these tests: main's no-raw-intl-locale rule keeps its test-oracle allowlist inside the rule, and this file is not on it. The oracle was also the wrong side: with no InternationalizationProvider mounted, useLocale() resolves to 'en', so the hook's labels never followed the machine locale that Intl.DateTimeFormat(undefined) reads. Literal 'April 2026' style assertions match Calendar.test.tsx and drop the Intl dependency.
The problem
Every overlay owned its own Escape listener, so one press could dismiss two layers: a popover and the Dialog hosting it, or a modal and the modal it was opened from.
We had been fixing this per primitive, and that produced four parallel registries:
useFocusTrap's Escape stack (#3357, DOM-depth resolution added in #4375),lab/Drawer's own LIFO registry,useScrollLock's counter (#4788, landed for the same class of bug), and a fifth proposed in #4865. Each one coordinates a different subset of overlays and none of them know about each other.This is the single registry those collapse into — the "Dismissal / Escape stack in
LayerProvider" from the program plan in #3343.The design
One stack, one listener, one decision point.
useLayerDismissalregisters a layer while it is active.layerStackowns a singlekeydownlistener ondocumentand routes each press to the top-most layer. Layers no longer listen for Escape at all. That is the core change: "everyone listens and filters themselves out" is what forced thestopPropagation()choreography between element-level and document-level handlers, and it broke silently whenever one participant forgot.One press dismisses exactly one layer, with no per-component exceptions. A layer declares what it does with a press that reaches it:
escapeBehaviorclose(default)blockDialog purpose="required"— must not close, and must not let the press leak to a layer behind itI deliberately did not add a "dismiss but let the press continue" variant for hover layers. It is tempting (the user never opened the tip, so why should it eat their press?), but the asymmetry decides it: guessing wrong that way is destructive — someone dismissing a stray tooltip over a half-filled form loses the form — while guessing wrong the other way costs one extra keystroke.
A layer's place in the order is keyed to its identity, not to each registration. A layer re-registers whenever its depth or behavior changes — a
Dialogwhosepurposeflips fromundefinedtorequiredwhile it is open is the real case, and StrictMode remounts every effect once more on top of that. Counting registrations would hand it a fresh, higher place each time and promote it above the layers opened over it, so Escape would start hitting the dialog underneath instead of the modal on top. Order is keyed to the layer's identity instead. ThePurpose flips while openstory drives it.Ordering comes from the React tree, not the DOM.
LayerDepthProviderwraps each layer's own content, so anything opened from inside registers as nested. Context survives portals (DOM containment does not — a nested overlay routinely renders intodocument.body) and depth is fixed during render, so an inner and outer layer that mount in the same commit order correctly. Effect order can't do that: React runs child effects before parent effects, so the inner layer registers first and looks older.There is nothing to mount at the app root — the context defaults to
0and depth composes on its own. DOM containment remains a tie-break for bareuseFocusTrap, which renders nothing and so cannot provide depth.Presence is asked at press time, not inferred from registration. Hover layers register for their whole lifetime because their open state lags the DOM by a frame; they answer presence from the DOM instead. This is what makes "consume" safe — an idle tooltip sitting in the tree never claims an Escape.
The stack, not the browser, decides. It calls
preventDefault()on presses it handles, which suppresses the browser's own close-watcher — both<dialog>'scancelandpopover="auto"light-dismiss (verified in Chromium; the default action runs after propagation, so a bubble-phasepreventDefaultstill beats it). The alternative — leaning on the native top layer — only coversshowModal()andpopover="auto", which would leave non-modalshow()drawers,popover="manual"layers, and older browsers on a second, differently-behaved code path.A dismissal the browser starts on its own — the Android back gesture, the platform close watcher — still reaches
<dialog>'scancel, because the stack never saw a press to suppress. Dialog answers those with the same ordering:preventDefault()always, so the browser cannot close a controlled<dialog>behind React's back, then dismiss only when this dialog isisTopmost()and Escape-dismissible.A composing Escape is claimed, not ignored. An IME sends Escape to cancel a half-formed character, ahead of
compositionend, so no layer may act on it — but standing down is not enough. An unclaimed Escape is exactly what makes the browser raise its own close request, and that request lands oncancel, which has no composition state to read and dismisses on the same keypress. In Chromium a guard that only returns measures identically to no guard at all. So the stackpreventDefault()s the press and dismisses nothing, and it claims only while a layer is actually on screen: with nothing to protect, the press is not ours to take.Close requests that arrive with no keydown to read — the back gesture, the platform close watcher, or a composing Escape that content stopped before the stack saw it — are answered by
shouldDismissOnCloseRequest(), which adds "not mid-composition" to the top-most rule.Dialog,LightboxandMobileNavask it from theircancelhandlers, so that policy lives in the stack rather than in three copies of it. Composition is tracked from document-level composition events, because the DOM offers no way to ask; a blur clears it too, so acompositionendthe stack never sees cannot leave the flag stuck on and swallow every later back gesture. The flag is page-wide, so a composition in a field behind a non-modal layer also suppresses that layer's close requests — one keystroke to recover from, and the alternative cannot work for layers that expose no container.The listener is on the bubble phase, not capture, so content inside a layer can claim the press first. Editors are the motivating case: Monaco and the rich-text editor use Escape for their own find widget, and that must win over dismissing the host Dialog. Capture would take the press away from them. (Radix uses capture here; this is a deliberate divergence.)
Bugs fixed along the way
A Tooltip inside a Dialog closed the Dialog, not the tip.
useTooltiplistened ondocumentand neither prevented nor stopped the event, while Dialog's listener sat on the<dialog>element and fired first.A HoverCard trigger swallowed Escape whenever it merely had focus. Its keydown listener called
stopPropagation()on any Escape, open card or not, so focusing a trigger inside a Dialog silently ate the press.A HoverCard pinned open with
isOpenmade its host Dialog keyboard-unclosable. Introduced here, not onmain: a controlled card joined the stack, so it consumed every Escape — and the stack cannot dismiss it, because its visibility is the consumer's state. Three presses, nothing moved.Tooltipalready opted out for exactly this reason;HoverCardnow does the same (isEnabled: isOpen === undefined). jsdom cannot pin this one — it cannot answer:popover-open, so the presence probe reads false and the stack routes to the dialog whether the opt-out is there or not; the test passes with the fix reverted, so there isn't one. ThePinned hover card in modalstory and the row above are the pin.A HoverCard you had tabbed into took its host Dialog with it. The card's content wrapper ran its own Escape handler with a bare
stopPropagation(), which kept the press from the dialog's listener but not from the browser's close watcher — so one press closed the card and the dialog behind it. Only reachable once focus is INSIDE the card, which is why the trigger-focused path always looked right. The card is on the stack; itsonDismissnow also returns focus to the trigger, the one thing the local handler did that the stack did not.A lab
InfoTipinside a Dialog took the Dialog with it. The triggerstopPropagation()d Escape, so the stack never saw the press — but the browser's own close watcher still firedcancelon the dialog behind it, and one press left nothing on screen. The trigger now handles no keys at all and theTooltipit renders takes the press from the stack. This is the third of the three layers in [Bug] Escape closes the layer underneath for Lightbox, MobileNav and lab InfoTip #5168; Lightbox and MobileNav are the other two.An Escape cancelling an IME composition closed the layer, and everything typed into it. A CJK user backs out of a half-formed character several times a sentence, and the modal went with it.
mainhas the same bug:Dialog's guard returns without claiming the press, so the close watcher closes the dialog anyway. Nobody typing English ever sees it, which is why it has been shipping.BottomSheetgot the same fix by hand in fix(BottomSheet): guard standalone Escape against IME composition #5322 — the standalone sheet is not on this stack yet, so its own guard stays until it migrates.Test plan
Unit — three new files besides the ones below:
layerDismissalInvariants.test.tsx(15),layerDismissalFamilies.test.tsx(8, Lightbox/MobileNav/required Dialog on real mounts) anduseFocusTrapEscapeShim.test.tsx(11, pinning that the deprecated shim still answers about traps only). Plus 21 inuseLayerDismissal.test.tsx, each one "one Escape press, which layers reacted?": same-commit nesting, fall-through after the inner closes, unrelated layers, DOM-containment tie-break,closevsblock, presence skipping, both opt-outs, content claiming the press viapreventDefault, the IME guard, and that the stack leaves the event alone when nothing is open.Plus 4 in
Dialog.test.tsxthat mount realDialogs rather than synthetic layers: a modal inside a modal takes one Escape on the inner only, the next Escape takes the outer, and acanceldismisses the top-most modal but not one underneath it. The modal-in-modal Escape test fails against the pre-stackDialoghandler (the outer closes too) and passes here.Five of the 21 are the IME case: that the composing press is claimed, that it is left alone when no layer is on screen, and that a close request is declined mid-composition and again once focus leaves the field. Two more in
Dialog.test.tsxmount a realDialogwith a field; six are added there in total. Both halves are pinned separately — reverting thepreventDefaulthoist reds two of them, and dropping the composition check fromshouldDismissOnCloseRequestreds three. jsdom models neither composition nor the close watcher, so these pin the wiring only; the behaviour is measured below.Visual, in real Chromium (Playwright against local Storybook, 14 stories under
Core/Layer Dismissal) — one Escape press per row:requireddialog in a host modalScreenshots captured for each transition; scrim mean-luma steps confirm exactly one layer peeling off per press.
The
cancelpath is checked the same way, in Chromium 149: on the Modal-in-modal story,requestClose()— the platform close-watcher path the Android back gesture fires — closes the inner modal and leaves the outer, and does nothing when called on the outer while the inner is on top. Against the barepreventDefault()cancel handler, neither call closes anything.IME, in real Chromium — a Hangul composition driven into a real field through CDP
Input.imeSetComposition, then Escape. Same twelve rows before and after the change, on this branch:Dialogwith a fieldAlertDialogstopPropagations the press firstcancelfired)cancelfired, declined)requestClose()mid-compositionPlain Escape is unchanged on every regression row:
DialogandAlertDialogclose on one press, modal-in-modal peels one layer then the other, a popover in a modal closes the popover only, arequireddialog still moves nothing, andrequestClose()with no composition still closes. Screenshots of each transition captured and read.The boundary with layers that are NOT on the stack yet, in real Chromium — the worry was that a stacked layer inside an unstacked one would be the very double-dismiss this is meant to fix: the stack claims the press, and the unstacked host runs its own listener anyway. Measured on both sides, one Escape per row:
mainContextMenuopen inside aDialogContextMenuInfoTipshowing inside aDialogHoverCardinside aDialog, focus tabbed INTO the cardHoverCardpinned open withisOpeninside aDialogPopoveropen inside aBottomSheetDialogopen inside aBottomSheetNo row got worse in what is on screen, and two got better. The double-dismiss does not happen across the boundary, because every self-handling layer claims the press at element level and the stack stands down on an already-
defaultPreventedpress.ContextMenuis the exception that proves it — its listener is ondocumentand does not readdefaultPrevented, so it does fire alongside the stack, but only ever against the layer the stack just dismissed.What the boundary does still cost is the last two rows: a layer opened inside an unstacked host never gets the press, because the host takes it first. That is unchanged from
mainfor what the user sees, with one wrinkle worth knowing about — onmainthe innerDialogwas dismissed along with the sheet, and here it is not, so itsisOpenstaystrueand reopening the sheet brings it back. Not a new class of bug, but it is the strongest argument for migratingBottomSheetnext.Repo checks —
tsc --noEmitclean,eslintclean on all touched paths,pnpm check:repofully green (sync comments, package boundaries, changesets, use-client), pre-commit hook run.Full suite —
packages/core+packages/lab, 7211 passing after mergingmain(286 files, no failures). A handful of load-sensitive tests (TransferList, Table perf, TabList) flake under full parallel load on my laptop; I confirmed the same set flakes on cleanmainwith the change stashed, and all of them pass in isolation on this branch. DropdownMenu specifically — it ridesuseFocusTrap— passed 3/3 isolated runs (113 tests each).Scope / follow-ups
Deliberately limited to the primitive plus the families that exercise both behaviors:
Dialog,useFocusTrap(Popover, DropdownMenu + submenus),Tooltip,HoverCard. Lightbox, MobileNav and labInfoTipcame along because #5168 is one bug across three layers and fixing two of them is not fixing it.Still self-handling, to migrate next:
BottomSheetfirst — it is the one measured above where a layer opened inside it never gets the press, and migrating it is also what lets fix(BottomSheet): guard standalone Escape against IME composition #5322's hand-rolled IME guard go.lab/Drawer,CommandPalette,ContextMenu,DropdownMenuSubMenu,PowerSearchEditPopover. The standalone sheet keeps the hand-rolled IME guard fix(BottomSheet): guard standalone Escape against IME composition #5322 gave it until then — collapsing it into the stack means migrating the sheet, not deleting a check.The hover-layer family is untestable in jsdom, and that is worth fixing separately.
Tooltip/HoverCardanswer presence withel.matches(':popover-open')behind a try/catch, on the assumption that an environment without the Popover API throws. jsdom returnsfalseinstead, so the fallback never runs and every hover layer reads as absent — which is why nothing in the new Layer suite mounts one, and why the controlled-card case above has a story rather than a test. Feature-detectingshowPopover(whatuseLayer.tsx:492already does) fixes it, but it is not a one-liner: it makes previously-invisible layers visible to existing tests and reds 9 inDateInputTouch.test.tsx— as timeouts, not failed assertions, so it wants a bug hunt rather than a test update (that file mounts a lifetimeuseTooltipfor its disabled message, which the swap makes visible to the stack for the first time). Measured, then reverted — a follow-up, not this PR.hasActiveFocusTrapEscape()is kept and deprecated. It deliberately still counts focus traps ALONE rather than every stacked layer: the stack now carries families that never trapped focus, and counting those would tell its one remaining caller (BottomSheetSwitcher) that a trap sits above it when none does.Outside-press, focus restore, and scroll-lock are the other channels #3343 wants on this stack; #4788 landed a counter for scroll-lock, which is the next one to fold in. The entry shape is ready for them; this PR does not build them.
Supersedes #4865, which fixed the modal-in-modal case with a fifth parallel registry. Two things came across from it, with thanks to @freddymeta: gating the
cancelhandler onisTopmost()so a browser-initiated dismissal still closes the top-most modal, and the Dialog-level modal-in-modal Escape test — the only realDialogmount guarding nested dismissal in either PR.Known edges
A layer keeps its place in the order for as long as its identity lives, so one that closes and reopens does not move to the top of a stack it was already in. Only reachable for a layer whose host stays mounted across the round trip, and only against layers registered after it.
A menu nested inside a dialog that stays open while a shallower second dialog opens would out-rank the new dialog. It requires the menu to still be open across the transition, which is unusual — noted rather than solved.