Skip to content

feat(core): one shared dismissal stack for every overlay layer - #4881

Merged
cixzhang merged 30 commits into
mainfrom
layer-dismissal-stack
Aug 24, 2026
Merged

cixzhang merged 30 commits into
mainfrom
layer-dismissal-stack

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

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.

useLayerDismissal registers a layer while it is active. layerStack owns a single keydown listener on document and 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 the stopPropagation() 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:

escapeBehavior Meaning Used by
close (default) dismiss this layer, consume the press modals, popovers, menus, tooltips, hover cards
block consume without dismissing Dialog purpose="required" — must not close, and must not let the press leak to a layer behind it

I 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 Dialog whose purpose flips from undefined to required while 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. The Purpose flips while open story drives it.

Ordering comes from the React tree, not the DOM. LayerDepthProvider wraps 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 into document.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 0 and depth composes on its own. DOM containment remains a tie-break for bare useFocusTrap, 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>'s cancel and popover="auto" light-dismiss (verified in Chromium; the default action runs after propagation, so a bubble-phase preventDefault still beats it). The alternative — leaning on the native top layer — only covers showModal() and popover="auto", which would leave non-modal show() 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>'s cancel, 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 is isTopmost() 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 on cancel, 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 stack preventDefault()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, Lightbox and MobileNav ask it from their cancel handlers, 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 a compositionend the 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. useTooltip listened on document and 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 isOpen made its host Dialog keyboard-unclosable. Introduced here, not on main: 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. Tooltip already opted out for exactly this reason; HoverCard now 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. The Pinned hover card in modal story 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; its onDismiss now also returns focus to the trigger, the one thing the local handler did that the stack did not.

  • A lab InfoTip inside a Dialog took the Dialog with it. The trigger stopPropagation()d Escape, so the stack never saw the press — but the browser's own close watcher still fired cancel on the dialog behind it, and one press left nothing on screen. The trigger now handles no keys at all and the Tooltip it 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. main has 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. BottomSheet got 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) and useFocusTrapEscapeShim.test.tsx (11, pinning that the deprecated shim still answers about traps only). Plus 21 in useLayerDismissal.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, close vs block, presence skipping, both opt-outs, content claiming the press via preventDefault, the IME guard, and that the stack leaves the event alone when nothing is open.

Plus 4 in Dialog.test.tsx that mount real Dialogs rather than synthetic layers: a modal inside a modal takes one Escape on the inner only, the next Escape takes the outer, and a cancel dismisses the top-most modal but not one underneath it. The modal-in-modal Escape test fails against the pre-stack Dialog handler (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.tsx mount a real Dialog with a field; six are added there in total. Both halves are pinned separately — reverting the preventDefault hoist reds two of them, and dropping the composition check from shouldDismissOnCloseRequest reds 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:

Story Result
Modal in modal (inner in outer's subtree) inner closes, outer stays → 2nd Escape closes outer
Popover in modal popover closes, modal stays → 2nd closes modal
Hover tip in modal, tip showing tip hides, modal stays → 2nd closes modal
Hover tip in modal, no tip showing modal closes immediately (idle tip claims nothing)
required dialog in a host modal nothing moves at all

Screenshots captured for each transition; scrim mean-luma steps confirm exactly one layer peeling off per press.

The cancel path 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 bare preventDefault() 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:

One Escape, mid-composition before after
Dialog with a field dialog gone, 한 with it dialog stands, 한 still composing
AlertDialog gone stands
Modal in modal, press in the inner inner gone inner stands
Content stopPropagations the press first gone (cancel fired) stands (cancel fired, declined)
requestClose() mid-composition gone stands

Plain Escape is unchanged on every regression row: Dialog and AlertDialog close on one press, modal-in-modal peels one layer then the other, a popover in a modal closes the popover only, a required dialog still moves nothing, and requestClose() 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:

One Escape main here
ContextMenu open inside a Dialog both close menu closes, dialog stands
Tooltip showing inside a ContextMenu tip only tip only
lab InfoTip showing inside a Dialog both close tip only, dialog stands
HoverCard inside a Dialog, focus tabbed INTO the card both close card only, dialog stands, focus back on the trigger
HoverCard pinned open with isOpen inside a Dialog dialog closes dialog closes (a controlled card is off the stack)
Popover open inside a BottomSheet sheet closes, popover does not same
Dialog open inside a BottomSheet both go sheet closes, dialog is left registered as open

No 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-defaultPrevented press. ContextMenu is the exception that proves it — its listener is on document and does not read defaultPrevented, 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 main for what the user sees, with one wrinkle worth knowing about — on main the inner Dialog was dismissed along with the sheet, and here it is not, so its isOpen stays true and reopening the sheet brings it back. Not a new class of bug, but it is the strongest argument for migrating BottomSheet next.

Repo checks — tsc --noEmit clean, eslint clean on all touched paths, pnpm check:repo fully green (sync comments, package boundaries, changesets, use-client), pre-commit hook run.

Full suite — packages/core + packages/lab, 7211 passing after merging main (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 clean main with the change stashed, and all of them pass in isolation on this branch. DropdownMenu specifically — it rides useFocusTrap — 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 lab InfoTip came along because #5168 is one bug across three layers and fixing two of them is not fixing it.

Still self-handling, to migrate next:

  • Comboboxes (Typeahead, Selector, MultiSelector, PowerSearch) — highest-frequency real bug; APG wants Escape to close the listbox and consume so a host Dialog doesn't close underneath.
  • The standalone BottomSheet first — 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/HoverCard answer presence with el.matches(':popover-open') behind a try/catch, on the assumption that an environment without the Popover API throws. jsdom returns false instead, 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-detecting showPopover (what useLayer.tsx:492 already does) fixes it, but it is not a one-liner: it makes previously-invisible layers visible to existing tests and reds 9 in DateInputTouch.test.tsx — as timeouts, not failed assertions, so it wants a bug hunt rather than a test update (that file mounts a lifetime useTooltip for 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 cancel handler on isTopmost() so a browser-initiated dismissal still closes the top-most modal, and the Dialog-level modal-in-modal Escape test — the only real Dialog mount 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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 11, 2026
@vercel

vercel Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 24, 2026 2:25am

Request Review

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Aug 11, 2026
@cixzhang
cixzhang force-pushed the layer-dismissal-stack branch 2 times, most recently from de1bb14 to f7582a1 Compare August 12, 2026 09:06
@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Dialog (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 654 -
Complexity N/A Very High (74) -
HoverCard (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 569 -
Complexity N/A Very High (69) -
Layer (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1214 -
Complexity N/A Very High (87) -
Lightbox (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 656 -
Complexity N/A Very High (84) -
MobileNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 457 -
Complexity N/A Very High (52) -
Popover (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 556 -
Complexity N/A Very High (52) -
Tooltip (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 523 -
Complexity N/A Very High (56) -
InfoTip (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 68 -
Complexity N/A Low (1) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB
@astryxdesign/lab N/A 3.5KB 1.5KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

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.
@cixzhang

cixzhang commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor Author

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 (layerStack.ts:224), but only five families are registered. Lightbox and MobileNav close via the native cancel event only, so once a required Dialog is on the stack, Escape stops reaching them. Same shape at Dialog.tsx:533 — cancel also fires for the Android back gesture, and that path no longer closes anything. Could the stack fall through when nothing registered claims the press?

hasActiveFocusTrapEscape went public in 0.4.2, and the shim changes what it means from "a trap is above me" to "any layer is present" — BottomSheetSwitcher.tsx:581 gates dismissal on it, so the sheet stops closing whenever a tooltip is up. Ideally I'd like to keep the shim trap-only and migrate the sheet properly in a follow-up.

Sizing: this is a lot at once. The stack + Dialog + useFocusTrap would carry Popover, DropdownMenu, PowerSearch and Typeahead on their own — Tooltip and HoverCard bring the presence-at-press-time machinery and the WCAG argument, which feels like its own PR.

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]

cixzhang and others added 2 commits August 17, 2026 08:24
`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]>
@github-actions github-actions Bot removed the needs:design-review Affects visuals — Design should review label Aug 17, 2026
github-actions Bot added a commit that referenced this pull request Aug 17, 2026
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.
github-actions Bot added a commit that referenced this pull request Aug 24, 2026
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.
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.
@cixzhang
cixzhang marked this pull request as ready for review August 24, 2026 01:58
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.
github-actions Bot added a commit that referenced this pull request Aug 24, 2026
github-actions Bot added a commit that referenced this pull request Aug 24, 2026
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>.
github-actions Bot added a commit that referenced this pull request Aug 24, 2026
@cixzhang
cixzhang merged commit 47d5160 into main Aug 24, 2026
19 checks passed
@github-actions
github-actions Bot deleted the layer-dismissal-stack branch August 24, 2026 04:19
@cixzhang cixzhang mentioned this pull request Aug 24, 2026
AKnassa added a commit to AKnassa/astryx that referenced this pull request Aug 27, 2026
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).
cixzhang pushed a commit that referenced this pull request Sep 3, 2026
…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.

This branch was successfully deployed

1 active deployment
Preview — 6bc04874 Deployed Aug 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant