Skip to content

[all components] Export data attribute and CSS variable metadata - #5608

Closed
atomiks wants to merge 1 commit into
mui:masterfrom
atomiks:claude/ecstatic-booth-ac9c7b
Closed

atomiks wants to merge 1 commit into
mui:masterfrom
atomiks:claude/ecstatic-booth-ac9c7b

Conversation

@atomiks

@atomiks atomiks commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closes #5242

Exports the DataAttributes/CssVars constants through a new opt-in subpath per component:

import { DialogPopupCssVars } from '@base-ui/react/dialog/metadata';

const style = { zIndex: `var(${DialogPopupCssVars.nestedDialogs})` };

Supersedes #5243 (thanks @superhooman), rebuilt on the ESM constants from #5248.

Why a separate subpath

Exporting from the existing entrypoints (the #5243 shape) costs +21.5 kB gzip total: the minifier can no longer inline the constants into their use sites, and @base-ui/react alone grows +9.8 kB (+6.6%). With the subpath, all 124 existing bundles are byte-identical; only consumers who import metadata pay for it. Attaching constants to the parts (Dialog.Popup.CssVars) was rejected for the same reason, with no way to opt out.

Changes

  • 34 metadata.ts files re-exporting the existing constant modules, flat file-derived names (DialogPopupCssVars).
  • Derived components re-export borrowed parts under their own prefix (AlertDialogPopupCssVars, ContextMenuItemDataAttributes), so each entrypoint is self-sufficient.
  • Root barrel intentionally excludes metadata; index.test.ts reflects that and asserts every exported constant resolves to a data-*/--* string.
  • Internal markers (e.g. data-drawer-content) stay private.

Docs reference tables for the new subpaths are left for a follow-up.

Bundle size

gzip
Existing 124 bundles ±0 B
New opt-in bundles (34) 205 B – 1.1 kB each

@atomiks atomiks added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: all components Widespread work has an impact on almost all components. labels Sep 1, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5608
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5608
    

commit: 0c34027

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

Total duration: 1,070.74 ms -22.19 ms(-2.0%) | Renders: 76 (+0) | Paint: 1,707.57 ms -78.64 ms(-4.4%)

Test Duration Renders
Popover mount (300 instances) 37.93 ms ▼-11.92 ms(-23.9%) 1 (+0)
Dialog mount (300 instances) 22.20 ms ▼-6.77 ms(-23.4%) 1 (+0)

13 tests within noise — details


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

@netlify

netlify Bot commented Sep 1, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 0c34027
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a96b8f34b237a00087248b2
😎 Deploy Preview https://deploy-preview-5608--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 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #5243. Production consumer checks found no added client JavaScript for selective imports with the barrel-export design, including clean Next.js webpack and Turbopack builds. The whole-entrypoint bundle reports retain every metadata export and overstate the cost to those consumers; the measured results and scope are recorded in the addendum to #5243.

@atomiks atomiks closed this Sep 17, 2026
@atomiks
atomiks deleted the claude/ecstatic-booth-ac9c7b branch September 17, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make CssVars and DataAttributes enums public

1 participant