Skip to content

[all components] Export CssVariables and DataAttributes - #5243

Merged
jjenzz merged 13 commits into
mui:masterfrom
superhooman:feature/public-css-vars-data-attributes
Sep 29, 2026
Merged

jjenzz merged 13 commits into
mui:masterfrom
superhooman:feature/public-css-vars-data-attributes

Conversation

@superhooman

@superhooman superhooman commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Related to #5242

35 components now export their CssVariables/DataAttributes constants publicly.

Includes component-specific aliases for borrowed Drawer and separator parts, a checked public export inventory with rendered-attribute tests, and a CSS-in-JS usage example in the styling handbook.


Tree-shaking and consumer cost

The barrel-export design was checked with production ESM consumer builds using the published packages at f25fa280 (this PR) and 0c34027c (#5608). For the latter, the comparison added its modern constant exports to the existing component barrels instead of requiring /metadata imports.

  • Vite 8.2.2: adding the exports produced byte-identical output (0 B parsed / gzip) for selective Dialog, Menu, Select, and Button imports from the root/component entrypoints, retaining the Dialog component namespace, and statically accessing parts through a namespace import. Both the existing enums and modern constants passed these comparisons.
  • Next.js 16.3.4 App Router: clean webpack and Turbopack production builds with the modern constants re-exported from the barrels produced byte-identical client JavaScript (0 B parsed / gzip). The fixture included Server and Client Component imports from root/component entrypoints. No custom optimizePackageImports configuration was used.

The bundle checker's default fixture imports and retains the entire entrypoint namespace (import * as everything; console.log(everything)), so all newly exported metadata survives. That case grew by 9,873 B gzip for the modern constants at the root entrypoint. It does not represent the cost to consumers whose unused exports are tree-shaken. Likewise, summing overlapping entrypoint deltas into a total consumer cost is misleading; the loss of constant inlining reported in #5608 did not occur in the selective-import comparisons.

A separate Vite fixture, before the public CssVariables rename, retaining all 199 metadata namespaces (974 entries, including derived-component aliases) produced 8,688 B gzip without any components. Much of the size is the retained public names, string values, and namespace getter/object machinery; it should not all be attributed to lost constant inlining. Accessing only DialogPopupCssVariables.nestedDialogs compiled to the literal string "--nested-dialogs" with no retained namespace object. A fresh build after the rename also confirmed that DialogPopupDataAttributes.open and the handwritten "data-open" literal produce byte-identical output. These are measured fixtures, not a fixed cost per application.

These zero-delta results apply to the tested production tree-shaken bundles. Unbundled Node ESM and CommonJS imports still evaluate the re-exported metadata modules, even when consumers select only a component; separate metadata subpaths would isolate that module-loading cost.

Separate /metadata subpaths are therefore unnecessary to protect the tested production client bundles. #5608 was closed in favor of this design. This PR has been rebased onto current master and updated to the current constants, with derived-component aliases and public export tests included. After completing the missing metadata exports, the selective Vite fixtures remain byte-identical; retaining the entire root entrypoint adds 10,037 B gzip. The current public inventory contains 205 metadata namespace exports with 982 entries, including aliases. Public export tests passed in jsdom and Chromium, alongside the package build, TypeScript, ESLint, Stylelint, API generation, documentation snapshot, and formatting checks.

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 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@5243
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5243
    

commit: cc3ca53

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+35.2KB(+7.70%) 🔺+10KB(+6.70%)

Details of bundle changes

Performance

Total duration: 1,069.14 ms -242.27 ms(-18.5%) | Renders: 76 (+0) | Paint: 1,785.63 ms -406.09 ms(-18.5%)

Test Duration Renders
Tabs mount (200 instances) 207.20 ms ▼-52.25 ms(-20.1%) 3 (+0)
Scroll Area mount (300 instances) 74.57 ms ▼-27.48 ms(-26.9%) 3 (+0)
Mixed surface mount (app-like density) 75.25 ms ▼-24.74 ms(-24.7%) 5 (+0)
Combobox type — 500 items, narrows to ~11 (type "Row 25") 29.97 ms ▼-9.96 ms(-24.9%) 15 (+0)
Combobox type — 500 items, all stay mounted (type "Row ") 26.17 ms ▼-8.34 ms(-24.2%) 11 (+0)

…and 1 more (+9 within noise) — details


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

@netlify

netlify Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

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

@superhooman

superhooman commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor Author

So, I tried to just straight up exporting these enums as is

But I have a questions:

  • Are we okay with no reexports from derived components like AlertDialog (Dialog) and Autocomplete (Combobox)? Since they use the same enums as underlying components
  • Should I place these exports in a separate barrel file? So it looks cleaner in the main one
  • Is it even worth it given it increases bundle size? Perhaps we can publish it as a separate package?

@superhooman
superhooman force-pushed the feature/public-css-vars-data-attributes branch from 94efb19 to f25fa28 Compare July 15, 2026 15:19
@zannager zannager added the scope: all components Widespread work has an impact on almost all components. label Jul 20, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 3, 2026
@jjenzz

jjenzz commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

hi @superhooman, we recently changed our exports to consts instead of enums. would you mind addressing the conflicts here to expose those instead? you might need to run pnpm docs:api when done too.

Are we okay with no reexports from derived components like AlertDialog (Dialog) and Autocomplete (Combobox)? Since they use the same enums as underlying components

things might be different now after our refactor, but i would personally expect comps to have their own equivalent named exports so that it's possible for AlertDialog to diverge from Dialog (if needs be) without a breaking change.

@atomiks what do you think?

Should I place these exports in a separate barrel file? So it looks cleaner in the main one

exporting from index is fine, they'll be tree-shaken.

Is it even worth it given it increases bundle size? Perhaps we can publish it as a separate package?

the const change we did aims to address some of that, but they will be tree-shaken so should be fine :)

@superhooman

Copy link
Copy Markdown
Contributor Author

Hi!
Sorry, just noticed this

I guess this PR should be closed as exporting is being done by @atomiks in #5608

@jjenzz

jjenzz commented Sep 17, 2026

Copy link
Copy Markdown
Member

@superhooman i think we agreed internally that your approach of exposing from the index.ts barrel files is preferred, is that correct @atomiks ?

@atomiks
atomiks force-pushed the feature/public-css-vars-data-attributes branch from f25fa28 to 12ffdc5 Compare September 17, 2026 23:34
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 17, 2026
@atomiks atomiks changed the title [all components] Export CssVars and DataAttributes [all components] Export CssVariables and DataAttributes Sep 18, 2026
@atomiks

atomiks commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Yes this approach works fine (treeshakes) after testing locally, so existing consumers don't pay the +10 KB increase reported by the bundle bot. Only those who want to import the metadata pay the cost.

I've renamed CssVars to CssVariables as DataAttributes isn't DataAttrs; it should likely spell out the full word for consistency now that it is public

jjenzz

This comment was marked as resolved.

@jjenzz

This comment was marked as outdated.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 22, 2026
Remove redundant metadata export assertions and move rendered-attribute checks into component suites.

Remove the duplicate Button data attributes module.
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 22, 2026
@jjenzz

This comment was marked as resolved.

@Janpot

Janpot commented Sep 23, 2026

Copy link
Copy Markdown
Member

Trying out a fix in #5784

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 29, 2026
@jjenzz

jjenzz commented Sep 29, 2026

Copy link
Copy Markdown
Member

Thanks @Janpot 🫶

@jjenzz
jjenzz force-pushed the feature/public-css-vars-data-attributes branch from 28fe87d to c2373d2 Compare September 29, 2026 15:47
@jjenzz
jjenzz force-pushed the feature/public-css-vars-data-attributes branch from c2373d2 to 61f5ed0 Compare September 29, 2026 15:51
@jjenzz
jjenzz merged commit 6a29b4b into mui:master Sep 29, 2026
24 checks passed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants