Repository navigation
feat(core): expose StyleX data token variables - #6832
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
6fa93b9 to
4cb1915
Compare
There was a problem hiding this comment.
Thank you for this change — exposing the 56 data colors as one public StyleX token object, with the plain JavaScript map generated from it and distribution CSS that only ships the group when a consumer actually uses it, is a clean solution to the "reference without a declaration" problem, and every existing token name, value, and JavaScript API is preserved.
Approval needs one maintainer decision first. This PR cites AST-051 as its governing specification, but that spec currently lives only on the stacked spec branch — it is not on main yet, and the token authority that is on main does not yet establish this new public import path, the canonical-source move, or the extraction change. Could a maintainer please provide or identify the governing specification on main for this addition (for example, by landing AST-051)? Once that is settled, the implementation can be approved against it — no removal or splitting is being asked for on this point.
Two smaller corrections are also needed:
- The distribution CSS extractor currently treats a type-only import (such as importing only the
DataTokenNametype) the same as a value import, which would ship all 56 defaults even though nothing uses them at runtime. Please exclude type-only imports/exports from that reachability scan and add a test case for it. - Please add a changeset for the new public export, following the repo's changeset format.
[Automated review]
| function staticStyleXImports(source) { | ||
| const specifiers = []; | ||
| const pattern = | ||
| /\b(?:import|export)\s+(?:[^'";]*?\sfrom\s*)?['"]([^'"]+\.stylex)['"]/g; |
There was a problem hiding this comment.
This reachability scan matches type-only statements too: import type {DataTokenName} from '@astryxdesign/core/theme/dataTokens.stylex' would queue the variable module and ship all 56 defaults even though a real compiler graph erases the import and uses nothing at runtime — contradicting the zero-when-unused guarantee. Four existing sources already use type-only .stylex imports, so the pattern is reachable today. Please skip import type / export type statements here (or strip them before matching) and add a fixture proving a type-only reference emits no variable group.
4cb1915 to
b396899
Compare
1d53454 to
952bfeb
Compare
b396899 to
3f9fd1f
Compare
PR Analysis Report
|
There was a problem hiding this comment.
Thank you for this change — exposing the 56 data colors as one public StyleX token object, with the plain JavaScript map generated from it and distribution CSS that only ships the group when a consumer actually uses it, is a clean solution to the "reference without a declaration" problem, and every existing token name, value, and JavaScript API is preserved. The two corrections from the previous review are also addressed: type-only StyleX imports no longer retain a variable group (with a fixture proving it), and a changeset now accompanies the new export.
Approval needs one maintainer decision first. This PR cites AST-051 as its governing specification, but that spec currently lives only on the stacked spec branch — it is not on main yet, and the token authority that is on main does not yet establish this new public import path, the canonical-source move, or the extraction change. Could a maintainer please provide or identify the governing specification on main for this addition (for example, by landing AST-051)? Once that is settled, the implementation can be approved against it — no removal or splitting is being asked for on this point, and no further code correction is outstanding.
[Automated review]
952bfeb to
9b84a70
Compare
3f9fd1f to
a472478
Compare
a472478 to
ed07388
Compare
ed07388 to
dcbc0be
Compare
There was a problem hiding this comment.
The data-token source, generated compatibility map, and public subpath match the current data-token contract, and Core's CSS now drops only the 56-variable data group (same rules otherwise).
One change before this lands:
- Following
.styleximports across packages also copies Core's own token groups into every satellite stylesheet. Built from this head,lab.cssgains 188 Core custom properties, andcharts.cssandrichtext.cssgain the same block: about 8.3 KB raw and 2 KB gzip each, so an app loading all three ships roughly 6 KB of gzip CSS thatastryx.cssalready declares. Charts' stylesheet grows from 1.4 KB to 9.8 KB. Acceptance: a satellite includes a cross-package variable module only when Core's own CSS omits it, so Lab still gets the data group when a component uses it, and the graph test covers the skip.
[Automated review]
Following .stylex imports across packages copied Core's token groups into lab.css, charts.css and richtext.css, which always load with astryx.css. A satellite now skips a variable module that Core's own graph already emits, so it still carries a group Core omits, such as the data tokens.
The export checker treats every package export outside its explicit list as stale, so the new dataTokens.stylex subpath sits beside tokens.stylex there.
User need
Astryx component authors need one public, compiler-visible data-color token object. Today the canonical values live only in a plain JavaScript map, so CSS consumers can construct a
var(--color-data-*)reference without causing StyleX to emit the declaration.Problem and solution fit
dataTokens.stylex.tsbecomes the checked-in canonical source and exportsdataVars.@astryxdesign/core/theme/dataTokens.stylexsubpath..stylexdependencies, so an unused group is absent and a referenced cross-package group is retained once. Lab, Charts, and RichText leave groups thatastryx.cssalready declares to Core's stylesheet.Current specification
Public delta and caller burden
The value remains
var(--color-data-categorical-green). StyleX 0.19 retains the complete semantic group: zero defaults when unused, all 56 when any member is used. This PR does not migrate consumers or remove theme-build defaults; those remain separate stacked changes.Existing
dataTokenDefaults,DataTokenName, theme validation, and JavaScript resolution keep their API and values, now generated from the StyleX source.Design and alternatives
The 56 names remain one group, matching Astryx's existing token-family model and the compiler's real
defineVarsgranularity. The accepted spec rejects per-token pruning claims, per-theme copies, a separate CSS defaults asset, and keeping the plain map as independent authority.Evidence
--color-data-*declarations because Core has no current data consumer.var(--color-data-categorical-green).Scope
Testing
pnpm vitest run scripts/generate-data-tokens.test.mjs scripts/build-css.graph.test.mjspnpm check:data-tokenspnpm check:token-docspnpm -F @astryxdesign/core buildpnpm -F @astryxdesign/core build:css(zero data declarations)pnpm check:package-boundariesgit diff --check