Skip to content

feat(core): expose StyleX data token variables - #6832

Merged
cixzhang merged 3 commits into
mainfrom
feat/data-vars-stylex
Oct 7, 2026
Merged

cixzhang merged 3 commits into
mainfrom
feat/data-vars-stylex

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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.ts becomes the checked-in canonical source and exports dataVars.
  • A generator derives the existing plain JavaScript compatibility map without importing the StyleX value module into ordinary theme graphs.
  • Core exports the focused @astryxdesign/core/theme/dataTokens.stylex subpath.
  • Package CSS extraction follows reachable .stylex dependencies, so an unused group is absent and a referenced cross-package group is retained once. Lab, Charts, and RichText leave groups that astryx.css already declares to Core's stylesheet.
  • Generated token docs expose the new public import and all 56 stable names.

Current specification

  • AST-066: FR1–FR3 and DEC-1–DEC-2.

Public delta and caller burden

import {dataVars} from '@astryxdesign/core/theme/dataTokens.stylex';

const positive = dataVars['--color-data-categorical-green'];

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 defineVars granularity. 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

  • Compiler fixture: a referenced cross-package variable module emits its complete group; an unreferenced module emits nothing; a group the provider package already emits is not repeated.
  • Satellite stylesheets built from this branch are byte-identical to the previous extraction (no Core token duplication).
  • Core all-component CSS contains zero --color-data-* declarations because Core has no current data consumer.
  • Built public module exports 56 stable variables; green resolves to var(--color-data-categorical-green).
  • Generated compatibility map and token docs fail their checks on drift.
  • Core build completed and the new export's JavaScript/types loaded; the repository-wide export verifier separately reported only pre-existing unbuilt CLI/theme artifacts.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm vitest run scripts/generate-data-tokens.test.mjs scripts/build-css.graph.test.mjs
  • pnpm check:data-tokens
  • pnpm check:token-docs
  • pnpm -F @astryxdesign/core build
  • pnpm -F @astryxdesign/core build:css (zero data declarations)
  • pnpm check:package-boundaries
  • full repository pre-commit validation
  • git diff --check

@vercel

vercel Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 7, 2026 9:36am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 1, 2026
@astracat-bot

astracat-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
⏳ Waiting for review (for maintainers only) Oct 7, 2026, 10:02 AM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 DataTokenName type) 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]

Comment thread scripts/build-css.mjs Outdated
function staticStyleXImports(source) {
const specifiers = [];
const pattern =
/\b(?:import|export)\s+(?:[^'";]*?\sfrom\s*)?['"]([^'"]+\.stylex)['"]/g;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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]

@cixzhang
cixzhang changed the base branch from spec/theme-build-boundary to main October 7, 2026 08:58
@cixzhang
cixzhang force-pushed the feat/data-vars-stylex branch from ed07388 to dcbc0be Compare October 7, 2026 08:58
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Oct 7, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 .stylex imports across packages also copies Core's own token groups into every satellite stylesheet. Built from this head, lab.css gains 188 Core custom properties, and charts.css and richtext.css gain 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 that astryx.css already 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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed: Lab, Charts, and RichText stylesheets no longer repeat Core's token groups and match the previous extraction byte for byte; the new graph test covers it.

[Automated review]

The export checker treats every package export outside its explicit list as stale, so the new dataTokens.stylex subpath sits beside tokens.stylex there.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the CI fix: the new subpath is now listed for the export checker, matching package.json. Still good to merge once checks pass.

[Automated review]

@cixzhang
cixzhang merged commit 01fb22f into main Oct 7, 2026
45 checks passed
@github-actions
github-actions Bot deleted the feat/data-vars-stylex branch October 8, 2026 06:25

This branch was successfully deployed

1 active deployment
Preview — 5b1e3456 Deployed Oct 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant