Skip to content

fix(Layer): a show that a browser-run hide wakes waits for that hide - #8543

Merged
cixzhang merged 5 commits into
meta:mainfrom
vjeux:fix/layer-browser-hide-ledger
Oct 31, 2026
Merged

cixzhang merged 5 commits into
meta:mainfrom
vjeux:fix/layer-browser-hide-ledger

Conversation

@vjeux

@vjeux vjeux commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

CI note: this head's checks were blocked by the repository's Actions policy (no jobs ran since 17:43Z); they need a re-run.

Why, what, how to check

Why. This comes from one product's effort to get its production JavaScript errors to zero: its log shows this one 12 times from 5 people in 7 days (9 on WebKit, 3 on Chrome). Pressing Escape inside an open popover throws it: the browser closes the popover and returns focus to its button, the tooltip there asks to open while the close still runs, and Chromium 151 and 156 refuse (149 does not). The tooltip stays closed.

What led here. The Popover API refuses a show while any popover shows or hides, and a hide returns focus inside that window. #6941 makes a show wait while useLayer runs its own show or hide; a close the browser runs itself (Escape, a tap outside) never entered that bookkeeping.

Options. (a) Catch the error and drop it: hides a real failure, and the tooltip still never opens. (b) Wait out every browser close before any show: tried first; it delayed a press that closes one menu and opens another, so focus no longer moved into the new menu. (c) Count the browser's close, try the show at once, retry after the close only if the browser refused. Chosen: it fixes the Escape case and keeps every other path as fast as before.

What. useLayer counts the browser's own popover closes in its ledger, from the close's start to its toggle event; a show refused during one replays after it, once.

How to check. Storybook Core/Layer → BrowserHideWakesAFocusLayer, Chromium 151+: Tab, Enter, Tab, Escape. Before: InvalidStateError in the console, no tooltip. After: no error, the tooltip shows.

Expected behavior and authority

architecture:layer-runtime (current): browser-initiated closes are observed through the queued toggle event; that holds. Restored: #6941.

Smallest restoration

  • popoverOperations.ts holds the ledger useLayer.tsx kept privately, plus the browser-close count and the replay, tested alone there. No public API, default, record or visual change.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 31, 2026 12:59am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 31, 2026, 1:12 AM UTC

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

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works for the story's Escape path: in Chromium 151 the base throws InvalidStateError and leaves the hint hidden, while this branch shows it with no error, and WebKit shows it on both. Two things need changing before approval:

  • endBrowserHide() also runs on every toggle-listener rebind (useLayer.tsx lines 1443 and 1517), so a closing layer whose host re-renders with a new onHide or onShow during the hide (for example an inline onHide plus a state update in the trigger's focus handler) still throws the same error in Chromium 151; please end the count only at the element's toggle or its removal, and add a test with an inline onHide.
  • The changeset, the story comment and the Playwright comment say a light dismiss hands focus back to the trigger, but a tap outside returns no focus, so only the close watcher's Escape (or another hide that returns focus) is affected; please correct the wording.

[Automated review]

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
Comment thread .changeset/layer-browser-hide-ledger.md Resolved
vjeux added 2 commits October 26, 2026 10:10
The Popover API refuses to show a popover while the document is showing or
hiding another one (Chromium 150+ throws an `InvalidStateError`, "Invalid to
show a popover during another show operation"). A hide hands focus back to
the element that had it inside that window, so a focus-driven layer on that
element (a tooltip on the trigger) asks to show inside it. `useLayer` already
defers a show that arrives inside a show or hide it runs itself, but a hide the
browser runs on its own, a light dismiss or an Escape its close watcher
answers, never passed through that ledger: the show ran at once, the browser
threw to the page, and the layer stayed closed.

The ledger moves to `popoverOperations.ts` and learns about browser-run hides
from the element's `beforetoggle`, which fires synchronously as such a hide
starts; the hide ends at the `toggle` the browser queues for the task after it,
or at the element's detach. A show that arrives inside any counted operation
waits in the ledger and replays once the document's last operation has ended
and the script that started it has unwound.
…ebind

A render inside the browser's hide (a focus handler setting state while an
inline `onHide` gives the hook a new `toggle` handler) made React rebind the
layer's listener and ref, and the count ended there, still inside the hide:
the parked show replayed and the browser threw again. The ledger now owns the
count's end: the element's own `toggle`, or the next task as the backstop for
an element that leaves the document before its `toggle` arrives, since the
hide itself is synchronous.

The changeset, the story and the spec no longer say a light dismiss hands
focus back: a tap outside returns no focus, so only a hide that restores
focus (the close watcher's Escape) wakes the layer.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Escape fix works: with this branch the story no longer throws InvalidStateError in Chromium 151 and the hint shows, and both changes requested on the previous revision are in. One blocking issue remains: a browser-run hide stays counted until the hidden element's toggle task, after the hide has already returned, so a press that light-dismisses one layer and opens another now defers that open; a DropdownMenu tapped open while a Popover is open no longer moves focus into the menu, and a useLayer caller that focuses into the layer right after show() finds it closed. Please defer only shows the engine actually refuses (for example when showPopover() throws InvalidStateError or leaves the element closed during a counted hide) and add a test in which one press closes a layer and opens another.

[Automated review]

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Component Size

Component Import before Import after Delta CSS before CSS after Delta
charts/Chart N/A 65.5KB N/A N/A 20B N/A
charts/ChartLegend N/A 54.8KB N/A N/A 20B N/A
charts/ChartTooltip N/A 54.7KB N/A N/A 20B N/A
core/AlertDialog 58.2KB 58.5KB +364B 12.6KB 12.6KB 0B
core/AppShell 67.5KB 67.9KB +376B 11.8KB 11.8KB 0B
core/Avatar 38.0KB 38.3KB +379B 6.3KB 6.3KB 0B
core/AvatarGroup 40.3KB 40.6KB +377B 6.5KB 6.5KB 0B
core/AvatarGroupOverflow 41.2KB 41.5KB +360B 6.4KB 6.4KB 0B
core/Banner 49.4KB 49.7KB +363B 10.1KB 10.1KB 0B
core/BaseTypeahead 55.9KB 56.2KB +346B 10.1KB 10.1KB 0B
core/BreadcrumbItem 68.3KB 68.7KB +370B 11.3KB 11.3KB 0B
core/Button 44.6KB 44.9KB +367B 9.3KB 9.3KB 0B
core/Calendar 56.5KB 56.9KB +368B 10.2KB 10.2KB 0B
core/Carousel 51.8KB 52.2KB +339B 10.4KB 10.4KB 0B
core/ChatComposer 62.3KB 62.6KB +346B 11.0KB 11.0KB 0B
core/ChatComposerInput 57.1KB 57.4KB +341B 10.2KB 10.2KB 0B
core/ChatComposerTokenElement 57.1KB 57.4KB +344B 10.2KB 10.2KB 0B
core/ChatDictationButton 48.1KB 48.4KB +371B 9.6KB 9.6KB 0B
core/ChatLayout 50.5KB 50.8KB +365B 10.1KB 10.1KB 0B
core/ChatLayoutScrollButton 48.0KB 48.3KB +367B 9.8KB 9.8KB 0B
core/ChatMessageList 29.3KB 29.3KB -1B 7.8KB 7.8KB 0B
core/ChatSendButton 47.3KB 47.6KB +359B 9.3KB 9.3KB 0B
core/ChatToolCalls 32.5KB 32.5KB 0B 9.1KB 9.1KB 0B
core/CheckboxInput 51.5KB 51.8KB +391B 9.5KB 9.5KB 0B
core/CheckboxList 46.8KB 47.1KB +393B 8.4KB 8.4KB 0B
core/CheckboxListItem 55.9KB 56.2KB +384B 10.8KB 10.8KB 0B
core/CodeBlock 62.4KB 62.7KB +356B 10.9KB 10.9KB 0B
core/CommandPalette 52.8KB 52.8KB 0B 12.0KB 12.0KB 0B
core/CommandPaletteInput 32.9KB 32.9KB 0B 8.3KB 8.3KB 0B
core/ComplexSelector 57.5KB 57.8KB +375B 10.8KB 10.8KB 0B
core/ContextMenu 76.2KB 76.6KB +348B 15.1KB 15.1KB 0B
core/DateInput 101.6KB 102.0KB +347B 15.0KB 15.0KB 0B
core/DateRangeInput 71.4KB 71.7KB +340B 11.4KB 11.4KB 0B
core/DateTimeInput 111.9KB 112.2KB +342B 15.4KB 15.4KB 0B
core/DialogHeader 50.4KB 50.8KB +395B 10.0KB 10.0KB 0B
core/DrawerHeader 50.5KB 50.9KB +379B 11.4KB 11.4KB 0B
core/DropdownMenu 74.1KB 74.5KB +387B 15.2KB 15.2KB 0B
core/DropdownMenuSubMenu 59.7KB 60.1KB +353B 9.8KB 9.8KB 0B
core/Field 44.9KB 45.3KB +385B 8.1KB 8.1KB 0B
core/FieldLabel 40.5KB 40.8KB +354B 6.7KB 6.7KB 0B
core/FileInput 55.7KB 56.1KB +382B 10.5KB 10.5KB 0B
core/Heading 9.1KB 9.1KB -1B 6.8KB 6.8KB 0B
core/HoverCard 17.3KB 17.6KB +350B 4.9KB 4.9KB 0B
core/IconButton 44.6KB 45.0KB +366B 9.3KB 9.3KB 0B
core/InputGroup 45.5KB 45.9KB +374B 8.2KB 8.2KB 0B
core/LayerProvider 64.9KB 65.3KB +363B 10.3KB 10.3KB 0B
core/Lightbox 52.8KB 53.2KB +367B 10.0KB 10.0KB 0B
core/Link 45.0KB 45.4KB +379B 7.8KB 7.8KB 0B
core/ListItem 55.3KB 55.7KB +385B 10.8KB 10.8KB 0B
core/Markdown 146.5KB 146.8KB +339B 18.0KB 18.0KB 0B
core/MobileNav 52.6KB 52.9KB +370B 10.2KB 10.2KB 0B
core/MobileNavToggle 47.8KB 48.2KB +359B 9.6KB 9.6KB 0B
core/MoreMenu 74.4KB 74.8KB +397B 15.2KB 15.2KB 0B
core/MultiSelector 74.3KB 74.6KB +328B 14.8KB 14.8KB 0B
core/NumberInput 57.4KB 57.7KB +376B 10.9KB 10.9KB 0B
core/Pagination 86.7KB 87.0KB +335B 15.6KB 15.6KB 0B
core/Popover 51.0KB 51.4KB +368B 12.2KB 12.2KB 0B
core/PowerSearch 168.3KB 168.6KB +351B 20.1KB 20.1KB 0B
core/ProgressBar 7.8KB 7.8KB -1B 6.6KB 6.6KB 0B
core/RadioList 46.3KB 46.7KB +383B 8.2KB 8.2KB 0B
core/RadioListItem 53.8KB 54.2KB +375B 9.9KB 9.9KB 0B
core/SegmentedControl 39.3KB 39.6KB +368B 6.3KB 6.3KB 0B
core/Selector 78.3KB 78.6KB +329B 15.3KB 15.3KB 0B
core/SideNav 65.5KB 65.9KB +365B 10.7KB 10.7KB 0B
core/SideNavCollapseButton 48.2KB 48.6KB +360B 9.6KB 9.6KB 0B
core/SideNavHeading 60.1KB 60.4KB +373B 10.4KB 10.4KB 0B
core/SideNavItem 56.2KB 56.6KB +370B 10.3KB 10.3KB 0B
core/Slider 49.2KB 49.6KB +389B 8.7KB 8.7KB 0B
core/Spinner 26.7KB 26.7KB -1B 7.5KB 7.5KB 0B
core/StatusDot 19.1KB 19.5KB +383B 6.2KB 6.2KB 0B
core/Stepper 49.0KB 49.3KB +361B 9.8KB 9.8KB 0B
core/Switch 49.9KB 50.3KB +392B 9.5KB 9.5KB 0B
core/TabList 40.8KB 41.1KB +376B 7.3KB 7.3KB 0B
core/TabMenu 56.8KB 57.2KB +345B 10.3KB 10.3KB 0B
core/Table 85.8KB 86.2KB +350B 15.8KB 15.8KB 0B
core/TableCell 77.4KB 77.8KB +350B 15.5KB 15.5KB 0B
core/TableHeaderCell 77.0KB 77.4KB +347B 15.3KB 15.3KB 0B
core/TableSelectionToolbar 53.7KB 54.1KB +397B 11.3KB 11.3KB 0B
core/Text 8.6KB 8.6KB -2B 6.8KB 6.8KB 0B
core/TextArea 50.1KB 50.5KB +388B 9.6KB 9.6KB 0B
core/TextInput 55.2KB 55.6KB +408B 10.6KB 10.6KB 0B
core/Thumbnail 52.3KB 52.6KB +383B 11.2KB 11.2KB 0B
core/TimeInput 88.8KB 89.2KB +361B 13.9KB 13.9KB 0B
core/Timer 9.2KB 9.2KB 0B 6.8KB 6.8KB 0B
core/Timestamp 28.0KB 28.0KB 0B 9.7KB 9.7KB 0B
core/Toast 61.5KB 61.8KB +363B 9.9KB 9.9KB 0B
core/ToggleButton 45.4KB 45.8KB +373B 9.4KB 9.4KB 0B
core/Tokenizer 70.0KB 70.3KB +361B 16.7KB 16.7KB 0B
core/Toolbar 40.2KB 40.6KB +385B 7.7KB 7.7KB 0B
core/Tooltip 16.9KB 17.3KB +361B 4.9KB 4.9KB 0B
core/TopNav 53.4KB 53.8KB +354B 10.5KB 10.5KB 0B
core/TopNavHeading 59.5KB 59.9KB +375B 10.2KB 10.2KB 0B
core/TopNavMegaMenu 55.9KB 56.3KB +349B 11.0KB 11.0KB 0B
core/TopNavMenu 59.2KB 59.5KB +351B 10.3KB 10.3KB 0B
core/Typeahead 63.1KB 63.5KB +370B 11.5KB 11.5KB 0B
lab/ChatEmojiPicker N/A 67.2KB N/A N/A 773B N/A
lab/ChatReactionBar N/A 67.7KB N/A N/A 1.1KB N/A
lab/CommentComposer N/A 96.1KB N/A N/A 1.9KB N/A
lab/CommentPin N/A 49.2KB N/A N/A 1.2KB N/A
lab/CommentThread N/A 218.5KB N/A N/A 2.4KB N/A
lab/Comments N/A 223.0KB N/A N/A 2.5KB N/A
lab/EmojiPicker N/A 65.2KB N/A N/A 722B N/A
lab/InfoTip N/A 22.3KB N/A N/A 458B N/A
lab/ListInput N/A 77.1KB N/A N/A 1.6KB N/A
lab/MobilePowerSearch N/A 155.6KB N/A N/A 1.2KB N/A
lab/MobileTokenizer N/A 94.7KB N/A N/A 880B N/A
lab/Schedule N/A 62.0KB N/A N/A 3.9KB N/A
lab/TourStep N/A 56.7KB N/A N/A 590B N/A
lab/TransferList N/A 69.1KB N/A N/A 1.7KB N/A
lab/TransferListSelector N/A 74.7KB N/A N/A 1.9KB N/A
richtext/RichTextEditor N/A 272.7KB N/A N/A 2.6KB N/A
richtext/RichTextEditorToolbar N/A 214.6KB N/A N/A 454B N/A
richtext/RichTextView N/A 253.1KB N/A N/A 2.3KB N/A

Sizes are gzip. Import counts the JavaScript the import loads eagerly; CSS counts the package stylesheet rules referenced by the modules it can load from its own package, lazily loaded ones included.

Bundle Size Summary

Gzip figures measure each package's entry file, not the code an import pulls in.

Package Entry (ESM) Entry gzip before Entry gzip after Delta
@astryxdesign/core 4.9KB 1.2KB 1.2KB 0B
Package stylesheet Gzip before Gzip after Delta
@astryxdesign/core 35.6KB 35.6KB 0B

Accessibility Audit

Status: The accessibility audit did not run on this pull request. It runs after merges to main and before each release; pull requests that touch components run it with the ci:heavy-lanes label.


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

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge: in Chromium 151 the story's Escape path no longer throws InvalidStateError and the hint shows, and a press that closes one layer and opens another, or a DropdownMenu opened over a Popover, behaves as on main in Chromium and WebKit. All four changes requested on earlier revisions are in. One optional touch-up: the changeset still says the hook "no longer asks the browser to show while that hide is still running", but it now asks once and replays the refused show after the hide, so that clause could say so.

[Automated review]

Comment thread .changeset/layer-browser-hide-ledger.md Resolved
…nly a show it refuses

The count of a browser-run hide outlasts the engine's own window: it ends at
the element's `toggle`, a task after the hide has returned, while the engine
accepts shows again as soon as the hide returns. Deferring every show inside
the count delayed a press that light-dismisses one layer at pointerup and opens
another at click: a DropdownMenu tapped open beside an open Popover no longer
moved focus into the menu, since it reads the open right after `show()`.

The ledger keeps the layers' own operations and the browser's hides apart.
A show inside one of the layers' own operations is still deferred ahead, as
meta#6941 did. A show inside a browser-run hide is asked of the browser first and
deferred only when the browser refuses it with an `InvalidStateError` (by
name, across documents). The replay runs outside the hide, so a replay that
fails is not caught; it runs one microtask per parked show, so one that throws
reaches the page alone and leaves the rest to run.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge: in Chromium 156 the BrowserHideWakesAFocusLayer story's Escape path no longer throws InvalidStateError and the focus-driven layer shows, while a tap outside, a press that closes one layer and opens another, and WebKit behave exactly as on main. One optional touch-up: the changeset's example reads as the Popover component with a Tooltip on its trigger, which already recovers on main, so describing a light-dismissible useLayer layer whose Escape the browser answers would match what this fixes.

[Automated review]

Comment thread .changeset/layer-browser-hide-ledger.md Outdated
'@astryxdesign/core': patch
---

[fix] useLayer: a show that a browser-run popover hide refuses (Chromium 156 throws an `InvalidStateError`) is replayed once that hide has ended, so the layer ends shown. For example, pressing Escape inside a popover returns focus to its trigger, whose tooltip now opens instead of failing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this example reads as the Popover component with a Tooltip on its trigger, which already shows the tooltip after Escape on main (its Escape goes through the shared dismissal stack to the layer's own hide(), which #6941 covers). The case this patch fixes is a light-dismissible useLayer layer whose Escape the browser's close watcher answers, so an example along the lines of "pressing Escape inside a light-dismissible layer that handles no Escape itself returns focus to its trigger, whose tooltip now opens instead of failing" would match it.

The example read as a Popover with a Tooltip on its trigger, a case whose
Escape the Popover handles itself and whose tooltip therefore already waited
on main. The fix covers a layer whose Escape the browser's close watcher
answers; the sentence now describes that.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge: in Chromium 156, pressing Escape inside a light-dismissible layer now returns focus to its trigger with the trigger's Tooltip showing and no InvalidStateError on the page, while a tap outside, a press that closes one layer and opens another, and WebKit behave exactly as on main. The red CI checks come from the repository's Actions allow-list refusing actions/checkout@v7 and the setup actions, plus one case in packages/richtext/src/CodeBlockHeaderPlugin.test.tsx, a package this change does not touch, so they need a re-run rather than a change here.

[Automated review]

@vjeux
vjeux marked this pull request as draft October 29, 2026 22:45
@vjeux
vjeux marked this pull request as ready for review October 29, 2026 23:59
@vjeux
vjeux marked this pull request as draft October 30, 2026 03:37
… writing context read before the show)
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Oct 31, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge: in Chromium 151, pressing Escape inside a light-dismissible layer now returns focus to its trigger with the trigger's Tooltip showing and no InvalidStateError on the page, while a tap outside, a press that closes one layer and opens another, and WebKit behave exactly as on main. The three new useLayer cases fail against main's hook and pass here. Every CI job was skipped on this head, so the required checks still need a run before merging.

[Automated review]

@cixzhang
cixzhang marked this pull request as ready for review October 31, 2026 02:56
@cixzhang
cixzhang merged commit d669762 into meta:main Oct 31, 2026
139 of 143 checks passed
@vjeux
vjeux deleted the fix/layer-browser-hide-ledger branch October 31, 2026 04:41

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants