Repository navigation
[combobox][select] Decouple automatic unmounting from actionsRef - #5734
michaldudak merged 14 commits into
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,083.60 ms -212.13 ms(-16.4%) | Renders: 76 (+0) | Paint: 1,769.76 ms -379.68 ms(-17.7%)
…and 3 more (+7 within noise) — details 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. |
…ntOnClose docs - Make the unmount action a no-op once the popup has already unmounted, so a consumer that keeps calling it after the automatic unmount no longer receives onOpenChangeComplete(false) twice. - Attach preventUnmountOnClose through a cast like the other popup stores instead of a throwaway Object.assign. - Declare preventUnmountOnClose as a property so the generated API docs render it inline instead of leaking the AriaCombobox namespace and a bogus external type. - Update the animation handbook's manual unmounting example to call preventUnmountOnClose, link the component pages to it, and regenerate the components index. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- Make the shared forceUnmount a no-op once the popup is already unmounted, matching the guard added to Select and Combobox, so every popup's unmount action ignores calls made after the automatic unmount. - Clear the Select and Combobox opt-out flag when setOpen opens, mirroring createPopupOpenState, so a same-batch reopen starts a new close cycle without relying on a render. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
Approving from a DX perspective. I agree this is the correct direction. Sounds like a bugfix tbh, the coupling seems unexpected. I wonder if it's worth adding a dev warning for those who might now be calling unmount when the component is already unmounted though? e.g.:
Base UI:
unmount()was called after the popup had already unmounted. To control unmounting manually, calleventDetails.preventUnmountOnClose()inonOpenChangebefore callingunmount(). Learn more: https://docs...
I don't feel strongly here, so i'll leave it up to you :)
PR reviewThe new opt-out is lost for common controlled-state timing, so external exit animations can still be cut off. Repeated synchronous Bugs (2)1. 🔴 Controlled closes can lose or never receive the unmount opt-outLocation: if (open && preventUnmountingOnClose) {
setPreventUnmountingOnClose(false);
}
// ...
enabled: mounted && !open && !preventUnmountingOnClose,The opt-out is only established during an internal Direct programmatic closes have the same outcome: changing the controlled prop to Failure scenario: A controlled Select calls Fix: Preserve the opt-out until an actual reopen transition occurs, rather than clearing it merely because the current render is open. Also provide a persistent/manual mechanism that can be activated before prop-driven closes. Add regression coverage for deferred controlled updates and direct programmatic closes. 2. 🟠 The unmount guard is not synchronousLocation: const forceUnmount = useStableCallback(() => {
if (!mounted) {
return;
}
setMounted(false);
// ...
store.context.onOpenChangeComplete?.(false);
});
Failure scenario: Two animation completion or cleanup callbacks invoke Fix: Guard with state updated synchronously before callbacks run, such as a ref or the immediately updated store state. Add a test that calls VerdictRequest changes - controlled external-animation flows remain broken. 🤖 Review generated with Codex |
…nd add a close action - Store the opt-out flag in the Select and Combobox stores and derive it the way useOpenStateTransitions does, so an opt-out recorded while a controlled close is still pending (for example inside startTransition) is no longer cleared by the render that still sees open. - Add a close action to the Select, Combobox, and Autocomplete actionsRef, matching the other popups, so a programmatic close goes through onOpenChange and can opt out of unmounting. - Guard every unmount action on store state that is updated synchronously, so two calls in one batch complete closing once. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
@jjenzz Thanks, both reproduced and are fixed in f62085c. 1. Controlled closes losing or never receiving the opt-out
2. Non-synchronous unmount guard
Tests
|
…us unmount guard - Guard repeated unmount() calls with a ref that mirrors the rendered mounted state instead of writing mounted: false into the Select and Combobox stores synchronously. The extra store notification re-rendered every subscriber outside React's batch and made the Combobox input-inside-popup tests emit act() warnings in Chromium. - Add close to the hand-rolled actionsRef mocks in the Select tests and the public-types harnesses now that the Actions types require it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
i'll leave it to you to determine how pragmatic this is PR reviewOne merge-blocking lifecycle regression affects Select, Combobox, and Autocomplete. Targeted JSDOM reproductions failed for all three; 30 selected existing tests passed. Browser tests were not run. Bugs (1)1. 🔴 Batched reopening permanently disables unmountingLocation: SelectRoot.tsx:314, also AriaCombobox.tsx:953. if (!mountedRef.current) {
return;
}
mountedRef.current = false;
setMounted(false);When Failure scenario: An external animation finishes and its callback calls Fix: Resynchronize the guard on every committed render, including when reopening keeps VerdictRequest changes — reopening can permanently break subsequent popup cleanup. 🤖 Review generated with Codex |
…ecycle and fix the unmount guard Extract the close-cycle lifecycle into a `useUnmountAfterClose` hook used by `useOpenStateTransitions`, Combobox, Select, and Navigation Menu. The mounted mirror now resyncs on every commit, so calling `unmount()` while the popup is open (or in the same batch as a reopen) no longer blocks every later unmount. Port Navigation Menu to the same opt-out model: automatic unmounting with `actionsRef`, `preventUnmountOnClose()` on the change event details, and a `close()` action. Build the Autocomplete open-change details on its own `ChangeEventDetails` so `isItemPress` no longer leaks into its docs, and update the TypeScript handbook, Select page, and `actionsRef` JSDoc. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
PR reviewOne merge-blocking issue: Navigation Menu can discard the manual-unmount opt-out during an exit animation. Existing affected suites passed in jsdom and Chromium; two focused reproductions failed in both. Bugs (1)1. 🔴 Preserve the opt-out across repeated close requestsLocation: NavigationMenuRoot.tsx:224–225 if (nextValue == null) {
setPreventUnmountOnClose(shouldPreventUnmountOnClose());When the value is already Failure scenario: Close with Fix: Preserve the existing opt-out for redundant close requests until reopening or explicit unmounting. Add regression coverage for both repeated imperative closes and focus leaving during a manually managed exit. VerdictRequest changes — ordinary focus movement can break the promised manual-unmount lifecycle. 🤖 Review generated with Codex |
…uests A close requested while the value is already `null` (the trigger's blur after an imperative close, or a repeated `close()`) skips `onValueChange`, so the consumer can't opt out again. Don't overwrite the recorded opt-out in that case; it resets on reopen or on `unmount()` as before. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A stale exit-animation callback can call `unmount()` after a quick reopen. Running the host's unmount cleanup and the close completion against a live popup cleared the positioner anchor, replayed the enter transition, and fired `onOpenChangeComplete(false)` while open. Make `forceUnmount` a no-op while open; the later close still unmounts automatically. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ch commits Guarding `forceUnmount` on the rendered `open` dropped a close and an `unmount()` issued in the same batch, which the Select trigger's deferred close hits in Chromium. Force a re-render instead and unmount in the commit if the popup closed, otherwise drop the call. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
PR reviewNo findings. The previous Navigation Menu issue is fixed, and both reproductions now pass. Verified 856 jsdom tests, 1,007 Chromium tests, and 46 additional shared-popup lifecycle tests. The full repository suite was not run. VerdictApprove — the updated lifecycle handling resolves the reported bug without any new verified regressions. 🤖 Review generated with Codex |
Restructure the JavaScript animations section of the animation handbook around the two choices a consumer makes: where the popup goes when closed and who ends the closing phase. Reduce the per-component "Closing animations" sections to a link, and reword the `unmount` action's JSDoc on Combobox, Autocomplete, Select and Navigation Menu to say it ends the closing phase rather than removes the DOM. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Combobox, Autocomplete and Select now mention the closing phase as a usage guideline bullet instead of a two-sentence section. Drop the `close()` sentence from the handbook's manual unmounting text. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
actionsRef
…lightItem mui#5734 decoupled automatic unmounting from `actionsRef`, so the notes, the demo's manual `unmount()` call and the regression guard that pinned the old coupling no longer apply. Keep `close` alongside `highlightItem` on the Combobox and Select actions. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Resolves conflicts with mui#5586 (highlightItem) and mui#5734 (unmount decoupling): - AriaCombobox: keep scrollItemIntoView alongside the new onNavigate source/inline handling; drop the now-unused useOpenChangeComplete import. - Combobox virtualized demos keep the built-in Virtualizer; the `imperative-action` scroll handling moves to the TanStack demos, and the docs note to the third-party section. - Add `imperative-action` to ListHighlightReason so imperative highlights scroll the built-in virtualizer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base UI only waits for animations it can detect on the popup element, so the framer-motion exit spring was cut on the Base flavor: the dropdown, dialog, color picker and tooltip disappeared in about 20ms at full opacity. Select and combobox kept theirs only because passing actionsRef used to hold the unmount, which 1.9 removed (mui/base-ui#5734). Installs already resolve 1.9, so they lost those animations too and failed to typecheck (Actions now requires close). - Every Base popup now calls eventDetails.preventUnmountOnClose() on close and releases the unmount from onAnimationComplete (plus the existing fallback timeout). - Popups with an open prop replay a close made by setting it through actionsRef.close(), so programmatic closes (the command menu picking a row, a form closing its dialog) animate too. - Select's acknowledge delay holds the unmount at press time; 1.9 keeps the opt-out until the delayed close lands. - Tooltip's exit target names x and y, so motion runs one exit animation instead of an instant reset that released the unmount early. - Checkbox group: Base UI 1.7+ stops its replayed click at the hidden input, so the square no longer stops the original click (it was swallowing the only click the row would get). - package.json and every registry item that uses Base UI now require @base-ui/react@^1.9.0, so installs and the site run the same version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #5587.
Passing
actionsRefto Combobox, Autocomplete, Select, or Navigation Menu currently disables automatic unmounting and the closingonOpenChangeComplete(false)callback. This makes accessing imperative actions implicitly require managing the popup lifecycle.Keep automatic unmounting enabled and add
eventDetails.preventUnmountOnClose()to the open-change event details, matching the other popup components. The opt-out applies to one close cycle and resets on reopening.Migration
Breaking for consumers that pass
actionsRefto keep the popup mounted during an externally controlled exit animation. This may affect projects using 3rd party animation libraries (like Motion) with Base UI. Explicitly prevent unmounting when closing:Continue calling
actionsRef.current?.unmount()when your animation finishes.onOpenChangeComplete(false)then fires at unmount; it is not the signal to invokeunmount(). Explicitly typed open-change handlers can useRoot.OpenChangeEventDetailsfrom the Combobox, Autocomplete, or Select namespace; Navigation Menu addspreventUnmountOnClosetoRoot.ChangeEventDetailsdirectly.actionsRefalso gains aclose()action, matching the other popups. Settingopen={false}(orvalue={null}for Navigation Menu) directly never calls the change handler, so there is no opportunity to opt out of unmounting. When closing programmatically, callactionsRef.current?.close()instead: it closes with theimperative-actionreason and runs the handler above. TheActionstype now requiresclose, so hand-written{ unmount() {} }ref stubs need aclosemember.The opt-out survives a controlled close that is applied later, for example inside
startTransition. Callingunmount()more than once in the same batch completes closing once, and calling it while the popup is open (or in the same batch as a reopen, as a late exit-animation callback might) does not affect later closes.Consumers relying on automatic CSS closing animations/transitions need no migration.
Implementation
The close-cycle lifecycle (transition status, the opt-out flag, the guarded
unmount, and the close-completion hook) now lives in one internaluseUnmountAfterClosehook.useOpenStateTransitions(Popover, Menu, Dialog, Tooltip, Preview Card, Drawer) and the Combobox, Select, and Navigation Menu roots all call it, so the four popups share one implementation instead of three copies.