Skip to content

[all components] Reduce popup bundle size - #5233

Merged
atomiks merged 9 commits into
mui:masterfrom
atomiks:codex/reduce-popup-bundle-size
Jul 16, 2026
Merged

[all components] Reduce popup bundle size#5233
atomiks merged 9 commits into
mui:masterfrom
atomiks:codex/reduce-popup-bundle-size

Conversation

@atomiks

@atomiks atomiks commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This reduces the code shipped by positioned popup components without changing their public APIs.

Changes

  • Reuse the supplied floating root store instead of constructing an unused root context.
  • Load adaptive-origin positioning only when a popup viewport is mounted.
  • Specialize reference hiding for Base UI's reference-hidden behavior.
  • Remove redundant popup subscriptions, refs, prop merges, and dialog context wiring.

@atomiks atomiks added performance scope: all components Widespread work has an impact on almost all components. labels Jul 14, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

commit: 61d24e4

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-772B(-0.17%) ▼-228B(-0.16%)

Details of bundle changes

Performance

Total 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.

@netlify

netlify Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 61d24e4
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a5888cfe06bde0008c80f42
😎 Deploy Preview https://deploy-preview-5233--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.

@atomiks
atomiks marked this pull request as ready for review July 16, 2026 05:37
@atomiks
atomiks requested review from Copilot and removed request for colmtuite, flaviendelangle, jjenzz and michaldudak July 16, 2026 05:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 useBaseUIFloating path 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.

@atomiks
atomiks merged commit 43d11eb into mui:master Jul 16, 2026
23 checks passed
@atomiks
atomiks deleted the codex/reduce-popup-bundle-size branch July 16, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance scope: all components Widespread work has an impact on almost all components.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants