[all components] Reduce popup bundle size - #5233
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,467.10 ms +53.98 ms(+3.8%) | Renders: 78 (+0) | Paint: 2,272.47 ms +83.87 ms(+3.8%) No significant changes — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR reduces the amount of code shipped for positioned popup components by reusing existing Floating UI root stores, deferring adaptive-origin positioning until a viewport is present, and removing redundant wiring—without changing public APIs.
Changes:
- Introduces an internal
useBaseUIFloatingpath to avoid constructing an unused internal root context when a root store is already supplied. - Switches adaptive-origin positioning to be enabled by popup viewport mounting (via store state), and specializes “reference hidden” detection without pulling in Floating UI’s
hide()implementation. - Simplifies popup interaction prop wiring and removes drawer/dialog context indirection by passing an explicit dialog mode.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/utils/usePopupViewport.tsx | Enables/disables adaptive-origin middleware on the popup store while the viewport is mounted. |
| packages/react/src/utils/useAnchorPositioningFallback.ts | Adds a fallback positioning path using the public useFloating hook (Navigation Menu). |
| packages/react/src/utils/useAnchorPositioning.ts | Refactors anchor positioning to accept an injected floating hook and uses useBaseUIFloating for Base UI’s internal path. |
| packages/react/src/utils/hideMiddleware.ts | Reimplements reference-hidden detection to avoid importing Floating UI’s hide() middleware. |
| packages/react/src/utils/hideMiddleware.test.ts | Adds tests to ensure the custom hide middleware matches Floating UI’s behavior (plus Base UI’s all-zero rect behavior). |
| packages/react/src/utils/adaptiveOriginMiddleware.ts | Moves DEFAULT_SIDES to a shared constants module. |
| packages/react/src/utils/adaptiveOriginConstants.ts | Adds DEFAULT_SIDES constant export (as const). |
| packages/react/src/tooltip/store/TooltipStore.ts | Replaces hasViewport store state with adaptiveOrigin middleware storage. |
| packages/react/src/tooltip/root/TooltipRoot.tsx | Removes prop merging for focusable popup props; uses EMPTY_OBJECT fallback for interaction props. |
| packages/react/src/tooltip/positioner/TooltipPositioner.tsx | Reads adaptiveOrigin from the store instead of importing middleware directly. |
| packages/react/src/tooltip/positioner/TooltipPositioner.test.tsx | Adds browser-only tests for transform vs top/left positioning and viewport mount/unmount updates. |
| packages/react/src/tooltip/popup/TooltipPopup.tsx | Ensures FOCUSABLE_POPUP_PROPS are applied at the popup element. |
| packages/react/src/preview-card/store/PreviewCardStore.ts | Replaces hasViewport store state with adaptiveOrigin middleware storage. |
| packages/react/src/preview-card/root/PreviewCardRoot.tsx | Removes prop merging for focusable popup props; uses EMPTY_OBJECT fallback for interaction props. |
| packages/react/src/preview-card/positioner/PreviewCardPositioner.tsx | Reads adaptiveOrigin from the store instead of importing middleware directly. |
| packages/react/src/preview-card/positioner/PreviewCardPositioner.test.tsx | Adds browser-only tests for transform vs top/left positioning depending on viewport. |
| packages/react/src/preview-card/popup/PreviewCardPopup.tsx | Ensures FOCUSABLE_POPUP_PROPS are applied at the popup element. |
| packages/react/src/popover/store/PopoverStore.ts | Replaces hasViewport store state with adaptiveOrigin middleware storage. |
| packages/react/src/popover/positioner/PopoverPositioner.tsx | Reads adaptiveOrigin from the store instead of importing middleware directly. |
| packages/react/src/popover/positioner/PopoverPositioner.test.tsx | Adds browser-only tests for transform vs top/left positioning depending on viewport. |
| packages/react/src/navigation-menu/positioner/NavigationMenuPositioner.tsx | Switches Navigation Menu to the fallback anchor-positioning path and removes redundant refs/subscriptions. |
| packages/react/src/menu/store/MenuStore.ts | Replaces hasViewport store state with adaptiveOrigin middleware storage. |
| packages/react/src/menu/positioner/MenuPositioner.tsx | Reads adaptiveOrigin from the store instead of importing middleware directly. |
| packages/react/src/menu/positioner/MenuPositioner.test.tsx | Adds browser-only tests for transform vs top/left positioning depending on viewport. |
| packages/react/src/menu/popup/MenuPopup.tsx | Removes redundant state reads and simplifies popupElement setter via store setter helper. |
| packages/react/src/floating-ui-react/hooks/useFloating.ts | Adds useBaseUIFloating and internalizes shared logic to avoid unnecessary internal root-context creation. |
| packages/react/src/floating-ui-react/hooks/useFloating.test.tsx | Adds coverage for useBaseUIFloating store usage and reference preservation. |
| packages/react/src/drawer/root/DrawerRoot.tsx | Uses useRenderDialogRoot('drawer', ...) instead of wrapping Dialog.Root with drawer context. |
| packages/react/src/dialog/root/useRenderDialogRoot.tsx | Makes dialog mode explicit parameter and removes IsDrawerContext provider. |
| packages/react/src/dialog/root/DialogRootContext.ts | Removes IsDrawerContext export. |
| packages/react/src/dialog/root/DialogRoot.tsx | Always renders dialog mode via useRenderDialogRoot('dialog', ...). |
| packages/react/src/alert-dialog/root/AlertDialogRoot.tsx | Updates to useRenderDialogRoot('alert-dialog', ...) signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This reduces the code shipped by positioned popup components without changing their public APIs.
Changes