Skip to content

build(stylex): resolve workspace .stylex imports to their source, so cross-package markers match - #8324

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/f3-stylex-workspace-resolution
Oct 25, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/f3-stylex-workspace-resolution

Conversation

@vjeux

@vjeux vjeux commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

A lab component styled with a compile-time selector on a core marker, such as stylex.when.ancestor(':hover', indicatorScope), silently never matches. StyleX names a defineMarker (likewise defineConsts and hashed defineVars) after the file that defines it, <package>:<path inside it>, and each import site recomputes that name from the file its specifier resolves to. Its commonJS resolution tries a bare specifier through Node resolution before any alias. Once core is built, lab therefore resolves @astryxdesign/core/Indicator/indicator.markers.stylex through core's exports "default" to dist/…stylex.js and names the marker xy4seo4, while core's build names it x1odsvnm from src/…stylex.ts. Lab's aliases are never reached. Storybook behaves the same, and whether it does depends on whether core happens to be built. Nothing on main references a core marker across packages yet; the first lab component that does would break.

Intended invariant

A workspace package's .stylex export has one name in every compile: the name the defining package's own build gives it.

Change

  • scripts/stylex-module-resolution.cjs (typed by its .d.cts): a StyleX custom resolution. A workspace specifier resolves to that package's exports source target (or src/<subpath>). Relative and other imports resolve as StyleX's do. Canonical names follow StyleX's own rule, so core's classes don't change.
  • It replaces the commonJS resolution wherever workspace source is compiled against another package's .stylex files: lab's, charts' and rich text's Babel builds (babel.config.json → babel.config.cjs), build-css.mjs, Vitest, Storybook (both configs), Sandbox, the docsite and the vibe-test apps. Core's own build is unchanged: it imports its .stylex files relatively, which already resolve to source.
  • test-build runs the Chromium check below after it installs Chromium.

Evidence

  • Failure before the change: with core built, lab's build compiles :where(.xy4seo4:hover *) against core's x1odsvnm. In Chromium, a lab child styled off core's marker stays red when the core owner is hovered.
  • Success after the change: the selector names x1odsvnm, and the child turns blue on hover.
  • Product/runtime behavior verified unchanged: core, lab, charts and rich text dist (JS and CSS) and Storybook's CSS are byte-identical before and after.

Owner question

An external app compiling against the published core with StyleX's default resolution also resolves dist/….stylex.js, so its compile-time selectors on core markers miss too. Should core name its markers by their published path? That's a packaging decision for core's owners; this pull request doesn't change it.

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/stylex-module-resolution.test.mjs, 15 cases:
    • a two-package fixture compiled with StyleX's commonJS resolution (names differ) and with the shared one (they match);
    • lab's real build against core's;
    • every config wired to the shared resolution;
    • the test-build step.
    • With lab's previous resolution, the real-build case fails.
  • ASTRYX_STYLEX_BROWSER=1 … stylex-module-resolution.browser.test.mjs: passes; fails with lab's previous resolution (Received: "rgb(255, 0, 0)").
  • pnpm build, then diff -r of the four packages' dist against main's build: identical. Storybook CSS md5 identical.
  • pnpm -F @astryxdesign/storybook typecheck: passes; the .d.cts types the resolution as StyleX's own custom ModuleResolution (the first push failed with TS7016). Sandbox's typecheck reports nothing from its config.
  • vitest run .github/scripts scripts packages/build: 2,144 passed. Docsite Babel compile, Storybook and Sandbox Vite configs load, lab's Vitest suite passes; eslint, prettier and the pre-commit repo checks are clean; changeset coverage: nothing ships.

…cross-package markers match

StyleX names a defineMarker (or defineConsts, or hashed defineVars) export
after the file that defines it, and an import site resolves its specifier to
compute the same name. Its commonJS resolution tries a bare specifier through
Node resolution before any alias, so once core was built, lab resolved
@astryxdesign/core/Indicator/indicator.markers.stylex to core's dist file and
named the marker xy4seo4 while core names it x1odsvnm: a compile-time
stylex.when.ancestor() on a core marker never matched.

scripts/stylex-module-resolution.cjs is a custom resolution that maps a
workspace package specifier to its exports `source` target (or src/<subpath>)
and keeps StyleX's canonical names, so core's own classes do not change. It
replaces the commonJS resolution in lab's, charts' and rich text's Babel
builds (now babel.config.cjs), build-css, Vitest, Storybook, Sandbox, the
docsite and the vibe-test apps. Core, lab, charts and rich text dist and
Storybook's CSS are byte-identical before and after: nothing on main
references a core marker across packages yet.

A node test compiles a two-package fixture both ways and lab's real build
against core's; a Chromium check in test-build hovers a core owner and reads
the lab child's color.
@vercel

vercel Bot commented Oct 24, 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 12:02am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 24, 2026
…that import it

Storybook's and Sandbox's configs import scripts/stylex-module-resolution.cjs,
which had no declaration (TS7016 in the storybook typecheck). The new .d.cts
declares it as StyleX's custom ModuleResolution, and filePathResolver now
returns undefined, as that type allows, when nothing resolves.
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 25, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 25, 2026
The lab test compiles a style keyed by the imported touch key with the
repository's shared StyleX resolution and asserts the emitted rule, not
just a class name: with core's dist present, a key read from compiled
output drops the arm silently (fixed by meta#8324, merged below).
vjeux added a commit to vjeux/astryx that referenced this pull request 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.

This looks ready to approve: the shared StyleX resolution makes lab's build name core's indicatorScope marker exactly as core's own build does, and the published core, lab, charts and richtext output is unchanged. The new unit and Chromium checks pass on this branch and fail when lab's previous resolution is put back, so they guard the fix. No changes are required; if you edit the description again, it could say that the docsite registry precompile, the vibe-test preview builder and astryx experimental render keep commonJS because they compile consumer code against published paths.

[Automated review]

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

46 of 504 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
RichTextEditor Markdown parity: side by side probe dark 556,900
RichTextEditor Markdown parity: side by side probe light 538,816
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 26 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

vjeux added a commit to vjeux/astryx that referenced this pull request Oct 25, 2026
@cixzhang
cixzhang merged commit 84702fc into meta:main Oct 25, 2026
65 checks passed
@vjeux
vjeux deleted the uikit/f3-stylex-workspace-resolution branch October 25, 2026 02:57
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 25, 2026
cixzhang pushed a commit that referenced this pull request Oct 25, 2026
…its provider (#8339)

## 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

- [x] No intended public API, product behavior, visual direction, or policy change.
- [x] Product changes discovered during the work were removed or split.
- [x] 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 #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.

This branch was successfully deployed

1 active deployment
Preview — 8c689c77 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