Skip to content

[popups] Unify popup open changes, store and Root - #5960

Merged
michaldudak merged 15 commits into
mui:masterfrom
michaldudak:popups-refactor/2-store-and-root
Oct 16, 2026
Merged

michaldudak merged 15 commits into
mui:masterfrom
michaldudak:popups-refactor/2-store-and-root

Conversation

@michaldudak

@michaldudak michaldudak commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Part 2 of 4 of the popup architecture refactor.

Before: Tooltip, Preview Card, Popover, Dialog and Menu each ran their own copy of the open-change sequence, and the copies had drifted apart. Menu even routed its open change through a string event that MenuRoot handled with component state. Each popup also kept a second store, a FloatingRootStore, that the Root's layout effect filled with copies of the open state, trigger and elements so the interaction hooks could read them. And each Root repeated the same ordered calls to create the store, sync controlled props, keep the active trigger current, run the open-state transitions and render its children.

After: BasePopupStore owns setOpen and the order of its steps, and each store overrides only the steps where it differs. The popup stores implement the interface the interaction hooks need (FloatingRootContext) themselves, so there is no second store and no copy. Every popup Root runs through usePopupRoot and renders its children through renderPopupRootChildren, so the Root's rules live in one module (popupRoot.tsx). Select, Combobox, NavigationMenu and Toast keep their FloatingRootStore.

How

  • Open-change module:
    • Menu's open change moves from MenuRoot into MenuStore; the 'setOpen' event and its listener are gone.
    • Every popup store runs its open change through BasePopupStore.setOpen: ignore check, close trigger, preventUnmountOnClose(), onOpenChange, cancel check, notifying the interactions, drop check, prepare, one commit (flushed synchronously for hover unless the store opts out), complete.
    • The drift is kept on purpose: Menu still ignores a delayed touch click only after reporting it, Popover still commits instantType in a second update, and Dialog's preventUnmountOnClose() still writes state as soon as it is called. applyPopupOpenChange is gone.
  • Folding FloatingRootStore:
    • FloatingRootContext becomes an interface holding only what the interaction hooks, the focus manager, the delay group and positioning use. FloatingRootStore implements it.
    • The popup stores implement it too, and parts hand the store straight to the hooks. The values match what the old copy settled on (last anchored trigger, client-point anchor, the positioner as the floating element). dataRef, events and nested move into the popup store's context, and syncOnly and useSyncedFloatingRootContext are gone.
    • useHoverReferenceInteraction reads the closing transition from the store, so the isClosing option is gone.
    • Positioning clears its elements through clearPositioning() on a PositioningRootContext interface. Both store kinds implement it, so positioning doesn't import FloatingRootStore, and Popover, Menu, Tooltip and Preview Card no longer bundle it.
  • Popup Root module:
    • The Root helpers move from popupStoreUtils.ts to popupRoot.tsx.
    • Each store resets its own fields on unmount by overriding prepareUnmount, committed with the shared fields in one update.
    • usePopupRoot runs every Root. The differences are options: closeOnActiveTriggerUnmount (Tooltip, Preview Card), disabled (Tooltip) and animateInitialOpen (Menu).
    • renderPopupRootChildren renders the handle attachment, interactions and payload children in one fixed order.
    • Store creation no longer takes a nested argument, since usePopupRootStore sets the flag on every render. Menu gates open changes on getCommittedOpenState alone, which the Root sets while it is mounted.
    • Glossary: adds Root.

Behavior

No intended user-visible change. The differences between components are kept on purpose.

Known observable notes:

  • The interaction hooks now see popup-store open changes in the same commit, instead of one Root layout effect later when the copy into FloatingRootStore ran.

🤖 Generated with Claude Code

@pkg-pr-new

pkg-pr-new Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

commit: 0c9f945

@netlify

netlify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 0c9f945
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ad1cb2fcb5047ded57461bc
😎 Deploy Preview https://deploy-preview-5960--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@michaldudak
michaldudak force-pushed the popups-refactor/2-store-and-root branch from a6fd88d to c3e6c7a Compare October 9, 2026 18:33
@michaldudak michaldudak added the internal Behind-the-scenes enhancement. Formerly called “core”. label Oct 9, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-2.76KB(-0.53%) ▼-799B(-0.47%)

Details of bundle changes

Performance

Total duration: 383.40 ms -0.66 ms(-0.2%) | Renders: 75 (▼-1) | Paint: 682.68 ms +2.64 ms(+0.4%)

Test Duration Renders
Menu open (500 items) 17.14 ms -0.63 ms(-3.5%) 10 (▼-1)

14 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 12, 2026
@michaldudak
michaldudak force-pushed the popups-refactor/2-store-and-root branch from c3e6c7a to 0a861c8 Compare October 12, 2026 10:43
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Oct 12, 2026
@michaldudak
michaldudak force-pushed the popups-refactor/2-store-and-root branch from 0a861c8 to 1f4941a Compare October 12, 2026 18:02
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Oct 12, 2026
@michaldudak
michaldudak force-pushed the popups-refactor/2-store-and-root branch from 1f4941a to e3522ab Compare October 13, 2026 07:53
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 13, 2026
@michaldudak
michaldudak force-pushed the popups-refactor/2-store-and-root branch from e3522ab to af80724 Compare October 13, 2026 08:48
@michaldudak
michaldudak marked this pull request as ready for review October 13, 2026 10:46
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 15, 2026
`MenuStore.setOpen` emitted a `'setOpen'` string event that `MenuRoot` listened
for in a layout effect and handled with component state. The store now runs
the open change itself, as the other popup stores do, so the event and its
listener are gone. The touch-close cooldown and the last open event move to
the store context.

The Root still decides two things the listener did, and exposes both to the
store through the context: a request made while the Root isn't mounted is
dropped, as an event with no listener was, and a repeated request is compared
against the state the Root last committed. The order of the steps is
unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Tooltip, PreviewCard, Popover, Dialog and Menu each ran their own copy of the
open-change sequence. `BasePopupStore` now owns `setOpen` and the order of
its steps:

1. `isOpenChangeIgnored`
2. `getCloseTrigger`
3. attaching `preventUnmountOnClose()` to the event details
4. `onOpenChange`
5. the cancel check
6. notifying the interactions
7. `isOpenChangeDropped`
8. `prepareOpenChange`
9. one commit, flushed synchronously for hover unless the store opts out
10. `completeOpenChange`

Each store overrides only the steps where it differs, so every popup keeps
its behavior, including where the copies had drifted apart:
- Menu still ignores a delayed touch click only after reporting the close to
  `onOpenChange` and the interactions.
- Popover still commits `instantType` in a second update.
- Dialog's `preventUnmountOnClose()` still writes state as soon as it is
  called, even when the close is then cancelled.

The last open-change reason is now shared popup state, and
`applyPopupOpenChange` is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…erface

`FloatingRootContext` was an alias of the `FloatingRootStore` class. It is now
an interface holding only what the interaction hooks, the focus manager, the
delay group and positioning use: reads of the open state, trigger, anchor,
floating element and id, `setOpen`, the client-point anchor, and the shared
`dataRef`, `events`, `nested` and trigger map.

`FloatingRootStore` implements it. Code that owns a real `FloatingRootStore`
(Select, Combobox, NavigationMenu, the popup store state and the anchor
positioning write-back) now names the class instead. Nothing changes at runtime.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Popup stores (Tooltip, PreviewCard, Popover, Dialog and Menu, plus the
components built on them) no longer create a `FloatingRootStore` or copy their
open state, trigger and elements into it from the Root's layout effect. They
implement `FloatingRootContext` themselves, and parts hand the store straight
to the interaction hooks, the focus manager and positioning.

- The hooks' reads come from popup state and keep the values the old copy
  settled on:
  - The DOM reference is the last trigger the popup was anchored to, kept after
    the popup unmounts.
  - The anchor is the client-point reference or else the active trigger. A
    client-point reference survives a close; one that followed the trigger
    follows the next trigger.
  - The floating element is the positioner (the popup for Dialog and Drawer),
    including a `keepMounted` positioner while closed. It is withheld only
    while an opening popup is still hidden, which the copy's one-commit lag
    used to cover.
- Anchor positioning still clears the DOM reference and the client-point
  reference while a `keepMounted` positioner is unmounted.
- `dataRef`, `events` and `nested` live in the popup store's context.
- `dispatchOpenChange` is one function both store kinds call, so `syncOnly`
  and `useSyncedFloatingRootContext` are gone.

Hooks now see a change in the same render instead of one Root layout effect
later.

Select, Combobox, NavigationMenu and Toast keep their `FloatingRootStore`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…nceInteraction

Popover, Menu, the submenu trigger, PreviewCard and Tooltip all passed
`isClosing: () => store.select('transitionStatus') === 'ending'`. Now that the
hook reads the popup store itself, its own fallback reads exactly that, so the
option and its test are gone. NavigationMenu, which never passed it, keeps
reading a `FloatingRootStore` that never reports a closing transition.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
claude and others added 10 commits October 16, 2026 08:58
Store creation, handle attachment, trigger ownership and open-state
transitions move from popupStoreUtils.ts to popupRoot.tsx unchanged, so
the next commits can build the popup Root module there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…opupStore

Popover, PreviewCard and Menu passed a callback to useOpenStateTransitions
to clear their own fields once the popup unmounted. They now override
prepareUnmount instead, and resetOnUnmount commits those fields with the
ones every popup resets in one update.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Popover, Tooltip, PreviewCard, Dialog and Menu each created their store,
synced the controlled props and callbacks, kept the active trigger
current, ran the open-state transitions and wired actionsRef with the
same ordered calls. usePopupRoot now does all of that from the props the
Roots share. What differs between Roots is passed as options:
closeOnActiveTriggerUnmount (Tooltip, PreviewCard), disabled (Tooltip)
and animateInitialOpen (Menu). Menu also passes its own floatingId
through usePopupRootWithFloatingId.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Popover, Tooltip, PreviewCard, Dialog and Menu each rendered the handle
attachment, their interactions and the payload children in a fixed
order. renderPopupRootChildren renders them, so the ordering rule lives
in the popup Root module, and the module only exports what Roots call.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
useAnchorPositioning no longer checks for FloatingRootStore to decide
which fields to clear while a keepMounted positioner is unmounted. A
PositioningRootContext interface adds clearPositioning() to the
interaction store for positioning only: FloatingRootStore clears all four
element fields, and popup stores clear the anchor element and anchor
override in one update. Popup families that use their own store no longer
bundle FloatingRootStore.
usePopupRootStore sets the store's nested flag on every render before
anything reads it, so the argument threaded through createStore, the
store constructors, createInitialContext and
createFloatingRootContextValues is gone. Menu's open changes are gated
on getCommittedOpenState alone: the Root sets it in a layout effect and
clears it on unmount, so rootMounted is gone too.

Also corrects the usePopupRootStore and PreviewCardHandleStore JSDoc.
… request gates

Covers both syncAnchorState branches, both resetOnUnmount branches with a
store's own unmount field, the floatingElement and referenceElement
selectors, and Menu's repeated, already-closed, unmounted and
trigger-less requests and its allowMouseEnter reset.
…n-change steps may return

Preview Card is checked for focus and dismiss, and Tooltip for dismiss.
A type spec pins which fields prepareOpenChange and prepareUnmount may
return.
- `createPopupStoreContext()` builds the context every popup store starts
  with, including its trigger map, so stores no longer create and pass a
  `PopupTriggerMap` themselves.
- `resetOnUnmount` builds the shared reset once, and Menu's close trigger reads
  the committed open state without a redundant optional call.
- `StoreInspector` serializes Maps and Sets in one branch.
- Tests cover what `dispatchOpenChange` sends and how it keeps the open event,
  a Menu `handle.open()` made in the commit the Root mounts, the synchronous
  hover commit and re-hovering during the exit transition for Tooltip and
  Menu, and focus when a `keepMounted` submenu reopens on hover.
- The `useImplicitActiveTrigger` and `createPopupOpenState` tests move next to
  their modules, sharing trigger helpers through `test/popupStoreTestUtils`.
@michaldudak
michaldudak force-pushed the popups-refactor/2-store-and-root branch from 0035eea to 0c9f945 Compare October 16, 2026 06:58
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 16, 2026
@michaldudak
michaldudak merged commit e01a106 into mui:master Oct 16, 2026
22 checks passed
@michaldudak
michaldudak deleted the popups-refactor/2-store-and-root branch October 16, 2026 07:06
flaviendelangle added a commit to flaviendelangle/base-ui that referenced this pull request Nov 2, 2026
Moves the drag engine's interactive-element selector import to the
relocated `utils/popups/constants`, applies master's stricter lint rules to
the branch's files, and marks the fake browser's paste focus test as an
expected failure: since mui#5960, a Menu closed through its controlled `open`
prop no longer notifies its Menubar, which then reopens it on focus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
flaviendelangle added a commit to michaldudak/base-ui that referenced this pull request Nov 19, 2026
Master (mui#5960, mui#6111) moved `useOpenStateTransitions` into popupRoot.tsx
and replaced its `onUnmount` callback with the store's `resetOnUnmount`.
Ported the deferred close check there: when an open request is pending at
unmount, `resetOnUnmount` and `onOpenChangeComplete(false)` now wait until
the request turns out to be ignored, and are skipped if it reopens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Behind-the-scenes enhancement. Formerly called “core”.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants