Repository navigation
[all components] Export CssVariables and DataAttributes - #5243
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,069.14 ms -242.27 ms(-18.5%) | Renders: 76 (+0) | Paint: 1,785.63 ms -406.09 ms(-18.5%)
…and 1 more (+9 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. |
|
So, I tried to just straight up exporting these enums as is But I have a questions:
|
94efb19 to
f25fa28
Compare
|
hi @superhooman, we recently changed our exports to
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 @atomiks what do you think?
exporting from
the |
|
@superhooman i think we agreed internally that your approach of exposing from the |
f25fa28 to
12ffdc5
Compare
|
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 |
This comment was marked as outdated.
This comment was marked as outdated.
Remove redundant metadata export assertions and move rendered-attribute checks into component suites. Remove the duplicate Button data attributes module.
This comment was marked as resolved.
This comment was marked as resolved.
|
Thanks @Janpot 🫶 |
28fe87d to
c2373d2
Compare
c2373d2 to
61f5ed0
Compare
Related to #5242
35 components now export their
CssVariables/DataAttributesconstants 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) and0c34027c(#5608). For the latter, the comparison added its modern constant exports to the existing component barrels instead of requiring/metadataimports.Dialog,Menu,Select, andButtonimports from the root/component entrypoints, retaining theDialogcomponent namespace, and statically accessing parts through a namespace import. Both the existing enums and modern constants passed these comparisons.optimizePackageImportsconfiguration 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
CssVariablesrename, 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 onlyDialogPopupCssVariables.nestedDialogscompiled to the literal string"--nested-dialogs"with no retained namespace object. A fresh build after the rename also confirmed thatDialogPopupDataAttributes.openand 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
/metadatasubpaths 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.