Repository navigation
fix(Layer): a show that a browser-run hide wakes waits for that hide - #8543
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
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 everytoggle-listener rebind (useLayer.tsxlines 1443 and 1517), so a closing layer whose host re-renders with a newonHideoronShowduring the hide (for example an inlineonHideplus 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'stoggleor its removal, and add a test with an inlineonHide.- 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]
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.
10f7db5 to
ffb3bd0
Compare
There was a problem hiding this comment.
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]
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewComponent Size
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 SummaryGzip figures measure each package's entry file, not the code an import pulls in.
Accessibility AuditStatus: The accessibility audit did not run on this pull request. It runs after merges to Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
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]
…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.
7ac2b0a to
62ef4c5
Compare
There was a problem hiding this comment.
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]
| '@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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]
… writing context read before the show)
There was a problem hiding this comment.
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]
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
useLayerruns 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.
useLayercounts the browser's own popover closes in its ledger, from the close's start to itstoggleevent; a show refused during one replays after it, once.How to check. Storybook
Core/Layer→BrowserHideWakesAFocusLayer, Chromium 151+: Tab, Enter, Tab, Escape. Before:InvalidStateErrorin 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 queuedtoggleevent; that holds. Restored: #6941.Smallest restoration
popoverOperations.tsholds the ledgeruseLayer.tsxkept privately, plus the browser-close count and the replay, tested alone there. No public API, default, record or visual change.Scope
Testing
useLayer.test.tsx"defers the show a browser-run hide wakes…" and "keeps counting…" fail; with option (b), "opens a layer at once…" fails;popoverOperations.test.ts"ends each hide exactly once…" fails withoutclearTimeout.LayerBrowserHide.a11y.chromium.spec.ts(3 cases) on this branch's Storybook build: 3 passed. CI's Playwright runs Chromium 149, which allows these shows, so there the spec passes on main too. On Chromium 156 the story's steps throwInvalidStateError … during another show operationon main, tooltip hidden, and show it with no error here; a tap outside closes the layer with no error on both; the press that closes one layer and opens another focuses the new one at once.packages/core/src/Layer/; a trial merge with feat(useCombobox): a combobox over a text field the caller renders #7732 is clean; the other two conflict with main on their own.