Skip to content

build(css): a package stylesheet inlines the constants it reads from its provider - #8339

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/f3-css-provider-consts
Oct 25, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/f3-css-provider-consts

Conversation

@vjeux

@vjeux vjeux commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

A lab (or charts, or rich text) style that reads a core defineConsts value fails the package CSS build: lab.css reads StyleX variables nothing declares: --xzatj5h. A satellite stylesheet leaves every core .stylex module that core's own components import to astryx.css. A constant, though, isn't a variable any stylesheet declares. StyleX compiles a read to a placeholder that only the constant's own rule resolves, and inlines it where it's read, so the placeholder stays in lab.css.

Intended invariant

A package stylesheet resolves every constant it reads, whichever package defines it. Variable groups stay in the stylesheet of the package that owns them.

Change

  • scripts/build-css.mjs: the reachable-file walk records the provider modules a package imports. Their defineConsts rules (rules carrying constKey/constVal) join the package's rule set. Constant rules emit no CSS.
  • The compile step is one shared function, so provider modules compile exactly as the package's own files do.
  • At-rule keys stay literal. StyleX puts an imported constant key in a later priority layer than the same literal media key, so core spells its touch and reduced-motion keys literally, and this change doesn't make imported keys a supported pattern.

Evidence

  • Failure before the change: a lab style reading layerViewportInset.gutterBlockStart (from @astryxdesign/core/Layer/layerViewportInset.stylex, a module core's layers import) fails build:css with the error above.
  • Success after the change: the same build passes, and lab.css carries the resolved calc(max(var(--spacing-4), env(safe-area-inset-top, 0px)) + …) with no var(--x…) left.
  • Product/runtime behavior verified unchanged: astryx.css and every package's dist are unchanged on main, since no package reads a provider constant there yet.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • scripts/build-css.graph.test.mjs, new case: a provider package with a constant and a variable group, and a satellite reading the constant as a transition-duration value.
    • Before the change: transition-duration:var(--x…) (fails).
    • After: 200ms, no undeclared variables, the provider's variable group absent.
  • build-css graph, layers and data-token tests: 19 passed.
  • The lab case above, on a branch with build(stylex): resolve workspace .stylex imports to their source, so cross-package markers match #8324 and core's constants: build:css exits 1 without this change, 0 with it.
  • Storybook and Sandbox builds pass with a lab component reading a core value constant. Storybook's stylesheet carries the resolved value, with no var(--x…) left.

@vercel

vercel Bot commented Oct 25, 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 25, 2026 5:24am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 25, 2026, 5:46 AM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 25, 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 automated review found no blocking issues: the provider-constant step and the shared StyleX resolution leave Core, Lab, Charts and Rich Text output byte-identical today, and the new graph case fails without the change and passes with it. The diff includes #8324, so landing #8324 first keeps this pull request to its build-css commit. One small fix: the comment above the provider-constants loop in scripts/build-css.mjs uses core's touch keys read as a media key as its example, which is the pattern the description says stays unsupported. A value read, such as layerViewportInset.gutterBlockStart, would make a clearer example.

[Automated review]

Comment thread scripts/build-css.mjs Outdated
Comment on lines +295 to +299
// A constant read from a provider's module (lab reading core's touch keys as
// a media key) compiles to a placeholder that only the constant's own rule
// resolves, and a constant is inlined where it is read. So the constants of
// every provided module this package imports join its rules (they emit no
// CSS); the module's variables stay in the provider's stylesheet.

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 example (core's touch keys read as a media key) is the case the description and the test comment at scripts/build-css.graph.test.mjs:130-131 say stays unsupported: an imported constant at-rule key compiles one priority step above the same literal key (.x8481of.x8481of:not(#\#) against .x1lpi7hw.x1lpi7hw). Consider a value read as the example, such as a layer gutter or a motion duration, and a note that at-rule keys stay literal.

…its provider

A satellite stylesheet (lab, charts, rich text) leaves every core .stylex
module to astryx.css. But a defineConsts value is not a variable any
stylesheet declares: StyleX compiles a read to a placeholder that only the
constant's own rule resolves, and inlines it where it is read. So a lab
transition timed by a core motion constant compiled to
`transition-duration:var(--x…)`, and build-css failed with "reads StyleX
variables nothing declares".

build-css now records which provider modules a package imports and adds
their constant rules to its own (constant rules emit no CSS); their
variable groups stay in the provider's stylesheet. At-rule keys stay
literal: StyleX gives an imported constant key a different priority than
the literal at-rule.

@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.

No blocking issues: the provider-constant step leaves astryx.css, lab.css, charts.css and richtext.css byte-identical today, and the new graph case fails without the change and passes with it. One small fix from the last round is still open: the comment above the provider-constants loop in scripts/build-css.mjs uses core's touch keys read as a media key as its example, which is the pattern the description and the test comment say stays unsupported, and which now compiles one priority step above the literal key instead of failing the build. Using a value read such as layerViewportInset.gutterBlockStart, plus a note that at-rule keys stay literal, would fix it.

[Automated review]

The example said lab reads core's touch keys as a media key, which is the
pattern this change keeps unsupported (an imported constant key compiles to
a different StyleX priority than the literal at-rule). It now names a
constant read as a value, the case the graph test covers, and says at-rule
keys stay literal.

@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.

No blocking issues: a Lab, Charts or Rich Text style can now read a Core defineConsts value and get it inlined in its package stylesheet, every package stylesheet builds byte-identical today, and the new graph case fails without the change and passes with it. The comment fix from the last round is in. Nothing else is needed; at-rule keys staying literal is still a convention no check enforces, so satellite styles should keep spelling them out.

[Automated review]

@cixzhang
cixzhang merged commit 513459a into meta:main Oct 25, 2026
64 checks passed
@vjeux
vjeux deleted the uikit/f3-css-provider-consts branch October 25, 2026 08:42

This branch was successfully deployed

1 active deployment
Preview — f2ba3d6d Deployed Oct 25, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants