Repository navigation
[dialog][alert dialog][drawer] Make the Root part own the store - #5109
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,354.31 ms -1.02 ms(-0.1%) | Renders: 78 (+0)
13 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 100fe447e4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e3973faec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
PR reviewThis PR fixes a real bug (#4951): a module-scoped Bugs (3)1. 🟡 Same #4951 bug still affects Popover and Menu handles (fix is Dialog-only)Location: // PopoverStore.useStore — routes through usePopupStore but passes only 3 args:
const { store, internalStore } = usePopupStore(externalStore, (floatingId, nested) => ...);
// MenuStore.useStore — never calls usePopupStore at all:
const internalStore = useRefWithInit(() => new MenuStore(...));
return externalStore ?? internalStore;
This is pre-existing and out of scope for a Failure scenario: A module-scoped Fix: Either file follow-up issues for Popover/Menu, or (for Popover) pass 2. ℹ️ Detached triggers briefly reference the orphaned
|
|
I'm going to fix Menu and Popover in separate PRs, not to keep this one open forever. |
PR reviewThis is a sound ownership-model refactor: each Bugs (4)1. 🟡 Imperative calls before a root attaches are silently dropped, with no production diagnosticLocation: openWithPayload(payload: Payload) {
if (this.attachedStore === null) {
if (process.env.NODE_ENV !== 'production') { console.warn(/* … */); }
return; // payload is discarded
}This is the intended fix for #4951 (the old shared store leaked stale open state), and it's documented. But it makes the natural "mount the root and open it in the same handler" pattern a no-op: Failure scenario: A user clicks a button whose handler both flips Fix: Confirm this tradeoff is intended (it appears to be). Worth considering defer-on-attach — stash the last 2. 🟡 The "more than one mounted root" warning can fire during overlapping route transitionsLocation: attachStore(newStore: DialogStore<Payload>) {
if (this.attachedStore !== newStore) {
if (process.env.NODE_ENV !== 'production' && this.attachedStore !== null) {
console.warn('Base UI: A handle is attached to more than one mounted root …');When an animated route/view transition keeps the outgoing screen mounted for a frame while the incoming screen mounts, two Failure scenario: A user with a module-scoped handle animates between two pages that each render Fix: Tolerate transient overlap — e.g. only warn if the previous store is still attached after a microtask/frame (i.e. the old root didn't unmount). At minimum add a test so the behavior is intentional (see Tests No. 1). 3. ℹ️ Minor breaking change: Handle constructors no longer accept a
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e43f5c5378
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This shouldn't be a real issue. I included a dev-time warning for now. If it's a problem, I'll introduce a solution but I don't want to bloat the implementation now.
Handles are meant to be created with the
This will be addressed in a separate PR. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7726a20f15
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
DialogHandle.open(triggerId) resolved the trigger element only from the attached root's store, so an open-by-id called from a layout effect in the same commit a root first attaches missed a still-mounted detached trigger that had not yet re-registered into the root store. The dialog opened unassociated and, with multiple detached triggers, another trigger could claim the popup first. Also resolve from the fallback store, where detached triggers stay registered until they migrate. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77fcd57223
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d0126cb68
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| (element: Element | null) => { | ||
| baseRegisterTrigger(element); | ||
| if (element) { | ||
| applyTriggerData(element); |
There was a problem hiding this comment.
Avoid claiming unassociated opens during migration
When a detached trigger re-registers because its handle store pointer changed, this also reapplies trigger data. If the root was opened imperatively without a trigger before the detached triggers have migrated (for example handle.open(null) or openWithPayload() from a layout effect in the same commit that the root attaches), activeTriggerId is still null and open is true, so applyTriggerData claims the first migrating trigger and can overwrite an openWithPayload() payload with the trigger's payload. That makes an explicitly unassociated imperative open become trigger-associated only during root attach/remount timing.
Useful? React with 👍 / 👎.
flaviendelangle
left a comment
There was a problem hiding this comment.
PR review
This PR reworks dialog/alert-dialog/drawer store ownership so each Root owns its store (via useRefWithInit) and the handle attaches/detaches as roots mount — fixing the stale-open-state-on-remount bug (#4951). After a four-area fan-out (bugs, tests, simplifications, docs), verifier passes, and an independent sweep, nothing is merge-blocking: no 🔴 regressions. The store-construction path faithfully reproduces the deleted useOnFirstRender initial-open / alert-dialog-invariant logic, attach/detach stack handling is correct under clean handoff, canceled overlap, and StrictMode replay, and trigger migration follows standard callback-ref semantics. The actionable items are test-quality nits.
Bugs (0)
No findings.
For completeness, the only candidate that survived to a note is dev-only and self-correcting: in packages/react/src/dialog/store/DialogHandle.ts:182, the lazily-created overlapWarningFrame is never cancelled on attachStore cleanup. This is benign — AnimationFrame.create() instances coalesce (request() calls this.cancel() first, so at most one pending frame), and the deferred callback re-checks this.attachedStores.length > 1 at fire time, so a settled handoff never warns spuriously. Gated behind NODE_ENV !== 'production', no user impact.
Tests (2)
1. 🟡 Weak warning assertion in the handle-switch test
Location: packages/react/src/dialog/root/DialogRoot.detached-triggers.test.tsx:1766
consoleWarn.mockClear();
await act(() => handleB.open('a'));
// ...
expect(aTrigger).toHaveAttribute('aria-expanded', 'false');
expect(consoleWarn).toHaveBeenCalled();After mockClear(), expect(consoleWarn).toHaveBeenCalled() only asserts that some warning fired, not the specific "No trigger found with id" message from DialogHandle.open. The behavioral assertion (aria-expanded === 'false') does pin the real contract, so the test isn't worthless, but the warning check itself is loose.
Failure scenario: if open-by-id regressed to emit an unrelated warning (e.g. an overlap warning) while still failing to associate the trigger, this assertion would still pass.
Fix: filter for the message, matching the other warning assertions in this file: expect(consoleWarn.mock.calls.some((c) => String(c[0]).includes('No trigger found'))).toBe(true).
2. 🟡 AlertDialog suite omits the detached no-op and payload-reset coverage that Dialog/Drawer have
Location: packages/react/src/alert-dialog/root/AlertDialogRoot.test.tsx:649
The Dialog and Drawer suites both assert (a) payload resets on remount and (b) the three "no root using this handle is mounted" warnings plus handle.isOpen === false while detached. The AlertDialog remount test asserts neither.
Failure scenario: a regression specific to AlertDialog's reset path (dropped payload-clearing, or imperative calls throwing/opening instead of no-op-warning while detached) would not be caught in the AlertDialog suite. Mitigated because AlertDialogHandle shares the exact DialogHandle code path that is covered in the Dialog file — so this is a coverage-parity nit, not a hole.
Fix: add a detached-imperative-no-op assertion and a payload-reset assertion to the AlertDialog remount test, mirroring the Dialog suite.
Additional ℹ️ gaps (optional): no test combines defaultOpen/defaultTriggerId with a handle-backed root (the useRefWithInit init path is covered by non-handle roots, and attach happens after init, so risk is low); the "payload dropped while detached" behavior is asserted only indirectly (the dropped value is never positively checked as absent on a later open); and the core remount-resets-state tests don't run under <React.StrictMode> (only the overlap path does).
Simplifications (1)
1. ℹ️ useDialogRootStore duplicates the floating-context setup from usePopupStore
Location: packages/react/src/dialog/root/useRenderDialogRoot.tsx:84 vs packages/react/src/utils/popups/popupStoreUtils.ts:51
useDialogRootStore re-implements useId + useFloatingParentNodeId + useSyncedFloatingRootContext + store creation almost verbatim from usePopupStore. usePopupStore is not dead — popover, tooltip, and preview-card still use it — so this can't be a delete. The two genuinely diverge in ownership model (usePopupStore is built around externalStore ?? createInternal; the new hook always owns the store and the handle attaches to it), so calling usePopupStore directly here would be more convoluted, not less.
Failure scenario: the floating-root wiring now lives in two places; a future change to it must be made twice. Low urgency — the duplicated surface is ~15 lines and the contracts legitimately differ. If addressed, extract just the useId/useFloatingParentNodeId/useSyncedFloatingRootContext block into a shared helper both call.
(The NullStore generic for one call site, the as any lazy-dev-field, the PopupTriggerDataStore Pick type, and the handle nominal brands were all reviewed and judged consistent with existing codebase precedent — no action needed.)
Docs (0)
No findings. The generated types.md files match source JSDoc, the removed store constructor param is fully scrubbed from all three components' types.md and the page.mdx index, the previous drawer copy-paste errors ("Dialog.Root…" → "Drawer.Root…", Drawer.Handle<Payload> prop type) are fixed, and the new "imperative methods require a mounted root" paragraph is consistent and accurate across dialog/alert-dialog/drawer. The author ran pnpm docs:api.
Verdict
Approve after nits — no regressions or correctness bugs; the only actionable items are two test-quality 🟡 nits (a loose warning assertion and AlertDialog coverage parity) and one ℹ️ duplication note.
🤖 Review generated with Claude Code
Assert the specific "No trigger found" message from DialogHandle.open instead of just toHaveBeenCalled(), matching the message-filtered warning checks elsewhere in the file, so an unrelated warning can't satisfy it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Updated.
Ignored. The logic in AlertDialog is basically the same as in the Dialog.
I'll clean it up when I treat Menu and Popover the same way. |
<!-- CURSOR_AGENT_PR_BODY_BEGIN --> ## Summary Upgrades `@base-ui/react` from `^1.6.0` → `^1.7.0` (latest as of Aug 4, 2026). No Frosted UI source changes were required. Validated locally: - `tsc` (CJS + ESM) ✅ - `eslint` + `stylelint` ✅ - `vitest` — 312/312 tests passing ✅ Sources: [Base UI v1.7.0 release notes](https://base-ui.com/react/overview/releases/v1-7-0), [GitHub release](https://github.com/mui/base-ui/releases/tag/v1.7.0), [CHANGELOG](https://github.com/mui/base-ui/blob/master/CHANGELOG.md). --- ## Breaking changes **Official changelog marks no 🚨 breaking changes in v1.7.0.** However, there are behavioral, API, and type changes consumers (and Frosted UI wrappers) should be aware of: ### Behavioral / DOM changes (potentially breaking in practice) 1. **`Accordion.Root` no longer sets an implicit `dir` attribute** ([#5117](mui/base-ui#5117)) - Previously `Accordion.Root` wrote `dir` onto the root. Direction now comes from the document / ancestor only. - Impact: CSS/JS that depended on `Accordion.Root[dir]` may stop matching. Pass `dir` explicitly if needed. 2. **`Combobox.Input` / `Autocomplete.Input` no longer inject `type="text"`** ([#5104](mui/base-ui#5104)) - Native `<input>` still defaults to text, but the attribute is no longer present in the DOM. - Impact: selectors like `input[type="text"]` will no longer match unless `type="text"` is passed explicitly. 3. **Listbox separators use `role="presentation"`** ([#5399](mui/base-ui#5399)) - `Select.Separator`, `Combobox.Separator`, and `Autocomplete.Separator` no longer expose `role="separator"` (axe/ARC compliance). - `Select.Separator` switched from a re-export of the generic `Separator` to a dedicated listbox separator component. - Public props (`orientation`, etc.) are preserved. 4. **Checkbox Group / Radio Group form values aligned with native submission** ([#5218](mui/base-ui#5218), [#5238](mui/base-ui#5238)) - Form payload shape may change vs prior Base UI behavior. Verify any custom form serialization that assumed the old values. 5. **Popup / overlay remount + handle reuse** - Dialog, Alert Dialog, Drawer, Menu, Popover, Preview Card, Tooltip no longer reopen after remounting with a reused handle ([#5109](mui/base-ui#5109), [#5149](mui/base-ui#5149)). 6. **Disabled state inheritance** - `Combobox.Item` / `Select.Item` inherit disabled from Root ([#5365](mui/base-ui#5365)). - `Menu` propagates disabled state to items ([#5363](mui/base-ui#5363)). 7. **`Field` keeps invalid state when disabled** ([#5116](mui/base-ui#5116)). 8. **`Select` no longer force-mounts the popup on programmatic value changes** ([#5119](mui/base-ui#5119)). ### API additions / changes | Area | Change | |---|---| | Autocomplete / Combobox | New `ChangeEventReason` values: `"input-press"`, `"cancel-open"` ([#5356](mui/base-ui#5356), [#5376](mui/base-ui#5376)) | | Autocomplete | New `form?: string` prop on Root (associates the internal input with an external form) | | Combobox | Exposes `aria-expanded` / expanded behavior for inline comboboxes ([#5332](mui/base-ui#5332)) | | Combobox / Autocomplete | New `.Separator` part | | Select | Dedicated `.Separator` part (listbox-safe semantics) | | Toast | `render` prop content now works on `Toast.Title`, `Toast.Description`, `Toast.Action` ([#5210](mui/base-ui#5210)) | | Modal docs | Touch-device modal scroll behavior clarified for Combobox / Select | ### Type changes 1. **`render` callback props specialized to the rendered element** ([#5104](mui/base-ui#5104)) - Third generic of `BaseUIComponentProps` now types callback props as the intrinsic element for: - `Avatar.Image` → `'img'` - `Form` → `'form'` - `NumberField.Input` / `OTPField.Input` → `'input'` - `PreviewCard.Trigger` / `Menu.LinkItem` / `NavigationMenu.Link` / `Toolbar.Link` → `'a'` - Polymorphic parts (e.g. `Combobox.Input`, `Field.Control`, button parts via `nativeButton`) remain loosely typed as `HTMLProps`. - May surface new TS errors if a `render` callback assumed looser props (or the reverse: more precise props like `src`/`href` are now available). 2. **Implementation-only types stripped from published `.d.ts`** ([#5165](mui/base-ui#5165)) - `@internal` declarations are no longer emitted. - Deep imports of internals (e.g. previously published helpers like `FloatingFocusManager`, `useAnchorPositioning`, numeral utils, store helpers) will fail typechecking if used. - Frosted UI does not depend on these internals. 3. **`AutocompleteRootChangeEventReason` / `ComboboxRootChangeEventReason` union widened** - Adds `"input-press"` and `"cancel-open"`. Exhaustive `switch`/`if` chains over reasons may need updates. 4. **Internal path moves** (only relevant for deep imports) - e.g. `useAnchorPositioning` moved under `internals/`; several utils relocated/removed from the public declaration graph. ### Frosted UI impact assessment | Concern | Status | |---|---| | Compile / typecheck against 1.7.0 | Passes with no source edits | | Existing `DialogRootActions` / `AlertDialogRootActions` imports | Still exported | | `useRender` / `mergeProps` | Unchanged public surface | | Autocomplete `keepHighlight` stories | Still valid (Autocomplete retains the prop; Combobox had removed it earlier in 1.6) | | Select.Separator wrapper | Compatible; benefits from a11y role fix automatically | --- ## What's new in `@base-ui/[email protected]` ### Features / enhancements - Typed `render` callback props based on the rendered element - Autocomplete locale-aware filtering - Autocomplete `form` prop for associating an external form - New Combobox / Autocomplete / Select listbox `Separator` parts (presentation role) - Combobox inline `aria-expanded` exposure - New open-change reasons: `input-press`, `cancel-open` - Scroll Area WebKit overscroll feedback on Thumb - Avatar Fallback shows immediately when `delay={0}` - Toast `render` prop support on Title / Description / Action ### Fixes (high level) - Popup positioning: collision padding off-by-one, unwanted flip with capped scrollable content, left-anchored auto-resize origin, unpositioned popups at viewport origin, canceled-exit unmount completion - Focus restoration after keyboard close in Safari/Firefox - Dialog touch outside-press without backdrop; scroll-lock handoff with external overlays - Drawer swipe/open reliability, iOS cross-axis scroll, Shadow DOM gestures, virtual keyboard scroll - Menu/submenu: duplicate `onOpenChange`, VoiceOver, TalkBack, pinch-zoom, Chrome mouseleave - Combobox/Select highlight/filter/scroll fixes (Safari hover highlight, grouped limit, query clear, disabled inheritance) - Field `data-dirty` for null-valued controls; Form focuses first invalid field in document order - Number Field multi-character format symbol editing - Progress custom `min`/`max` semantics - Slider assorted fixes; Tabs Suspense pre-hydration indicator - Toast timer / swipe / re-add / provider effect ordering - Navigation Menu frozen state when open trigger unmounts - Radio unnecessary ARIA attributes removed; internal input clicks no longer bubble (Checkbox/Switch/Radio) ### Performance / bundle size Across many components Base UI reduced parsed bundle size and avoided redundant work: - Shared popup / store / dialog / popover / field / form / meter / progress / scroll-area / slider / switch / tabs / toast / toolbar / toggle-group size reductions - Avoid redundant re-renders during lazy flipping - Remove redundant lifecycle synchronization - Exclude prehydration scripts from client bundles (Slider, Tabs) - Deduplicate Combobox/Select/Autocomplete handlers and swipe math --- ## Full v1.7.0 changelog (from upstream) ### General - Restore visible focus after keyboard close in Safari and Firefox (#5093) - Type `render` callback props based on the rendered element (#5104) - Reduce popup / store / shared popup bundle size (#5233, #5250, #5192) - Keep unpositioned popups at the viewport origin (#5299) - Correct layout and passive effect timing (#5337) - Remove redundant lifecycle synchronization (#5341) - Prevent stale cleanup from clearing registered part IDs (#5340) - Complete popup unmounting after a canceled exit transition (#5401) - Fix rendered trigger ID ownership (#5110) - Prevent unwanted flip with capped scrollable content (#5120) - Fix `collisionPadding` off-by-one on the biased side (#5143) - Mount popup subtrees synchronously when opening in React 17 (#5309) - Fix auto-resize origin for left-anchored popups (#5370) - Avoid redundant re-renders during lazy flipping (#5372) - Strip implementation-only types from published `.d.ts` files (#5165) - Fix `usePreviousValue` equality comparison (#5264) ### Components - **Accordion:** Remove implicit `dir` on Root (#5117) - **Alert Dialog / Dialog / Drawer / Menu / Popover / Preview Card / Tooltip:** Prevent reopen after remount with reused handle (#5109, #5149) - **Autocomplete:** Locale filtering; `input-press` / `cancel-open` reasons; reset scroll on filter; separator semantics - **Avatar:** Fallback immediate at `delay={0}` - **Button:** Keyboard click for custom elements - **Checkbox / Checkbox Group / Switch / Radio Group:** Click bubbling, validation, native form values, bundle size - **Combobox:** Filtering/highlight fixes; `expanded` for inline; disabled inheritance; separator; portalled content; bundle cleanup - **Composite:** Nested reorder, disabled nav skip, RTL scroll alignment - **Drawer:** Swipe/open, iOS scroll, Shadow DOM, snap points, bundle - **Field / Fieldset / Form:** Invalid-when-disabled, `data-dirty`, focus first invalid, bundle - **Menu:** Pinch-zoom, submenu hover/VO/TalkBack, disabled propagation, exit animation - **Meter / Progress / Toggle Group:** Formatting / min-max / bundle - **Navigation Menu:** Frozen menu on trigger unmount; pinch-zoom - **Number Field / OTP Field:** Format symbols; invalid autofocus when autoSubmit blocked - **Scroll Area:** Thumb drag, iOS visibility, overscroll feedback, snap while dragging - **Select:** Highlight/disabled/mount/separator fixes - **Slider / Tabs:** Assorted fixes; Suspense indicator; exclude prehydration from client bundles - **Toast:** Timer, swipe locking, re-add closing toast, `render` prop content, provider effect order --- ## Test plan - [x] Bump `@base-ui/react` to `^1.7.0` and refresh lockfile - [x] `pnpm --filter=frosted-ui exec tsc --project tsconfig-esm.json --noEmit` - [x] `pnpm --filter=frosted-ui build:js` (CJS + ESM) - [x] `pnpm --filter=frosted-ui lint` - [x] `pnpm --filter=frosted-ui test` (312 tests) - [ ] CI green on this PR - [ ] Spot-check Storybook surfaces that wrap Base UI heavily (Combobox, Select, Dialog, Menu, Toast, Accordion) if desired before merge <!-- CURSOR_AGENT_PR_BODY_END --> <div><a href="https://cursor.com/agents/bc-b799cb20-62b5-4aad-9033-e9e7a838d771?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a href="https://cursor.com/background-agent?bcId=bc-b799cb20-62b5-4aad-9033-e9e7a838d771&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </div> Co-authored-by: Cursor Agent <[email protected]>
Ports the six applicable Drawer fixes from the base-ui v1.7.0 release: - mui/base-ui#5105: reliable swipe-to-open — first-move re-anchoring is now gated on trackDrag (the SwipeArea passes trackDrag: false, so a flick whose whole travel lands in the first move still registers), and sawPrimaryButtonsOnMove initializes from the event type. - mui/base-ui#5308: drag styles are only rewritten when the offset actually changed, fixing the snap point jump when the pointer is pinned at a screen edge. The swipeThreshold function is snapshotted at gesture start. - mui/base-ui#5257: cross-axis touch arbitration rewritten (shouldYieldTouchMove) — 6px slop / 2px bias, one-shot attribution per gesture, non-cancelable moves yield to native scroll, and no preventDefault until an axis passes the slop (iOS kills native scrolling for the whole gesture otherwise). - mui/base-ui#5360: elementFromPoint resolves through getRootNode() so swipe gestures work inside shadow DOM. - mui/base-ui#5112: the popup no longer flashes fully open for a frame during a swipe-area open — resetAfterOpen skips the movement-var reset while the SwipeArea drives the gesture (swipeAreaActive), and the SwipeArea re-asserts its styles when the popup (re)mounts. - mui/base-ui#5179: virtual keyboard scroll handling rework for focus moves while the keyboard is open — interval realign passes, preemptive focus geometry override to neutralize WebKit's reveal scroll, window scroll pinning, programmatic-focus flag, settle-watching scroll bookkeeping. The SwipeArea outside-press guard is now deterministic (capture-phase pointerdown/click listeners + isVirtualClick) instead of a 300ms timer. Not ported (React-only): mui/base-ui#5109, Drawer.Handle/createHandle detached triggers, bundle-size refactors. Co-Authored-By: Claude Fable 5 <[email protected]>
Fixes #4951.
Summary
A module-scoped
Dialog.createHandle()used to preserve stale open state after its<Dialog.Root>was unmounted while open, so the next root mounted with the same handle reopened immediately.This changes the ownership model: each
<Dialog.Root>now creates and owns its own store (viauseRefWithInit) instead of reusing the handle's store. The handle holds a pointer to the currently mounted root's store and attaches/detaches as roots mount and unmount, so every mount starts from fresh state. Detached triggers follow the handle's store pointer and re-register into the attached root's store when it changes. Imperative handle methods (open,openWithPayload,close) are no-ops while no root is attached (with a dev-only warning), andisOpenreturnsfalse.Note
Using a single handle with two roots mounted at the same time is not supported: the most recently mounted root takes over (a dev-only warning is logged). Handles are expected to be stable and used by a single mounted root for their lifetime.
Changes
Dialog.Root(created once per root) and have the handle attach to it, so reused handles no longer carry stale state across remounts.