Repository navigation
build(stylex): resolve workspace .stylex imports to their source, so cross-package markers match - #8324
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
…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.
…he shared touch keys
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).
…he shared touch keys
There was a problem hiding this comment.
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]
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Visual Regression46 of 504 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
…he shared touch keys
…he shared touch keys
…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.
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 adefineMarker(likewisedefineConstsand hasheddefineVars) after the file that defines it,<package>:<path inside it>, and each import site recomputes that name from the file its specifier resolves to. ItscommonJSresolution tries a bare specifier through Node resolution before any alias. Once core is built, lab therefore resolves@astryxdesign/core/Indicator/indicator.markers.stylexthrough core'sexports"default" todist/…stylex.jsand names the markerxy4seo4, while core's build names itx1odsvnmfromsrc/…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
.stylexexport 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 StyleXcustomresolution. A workspace specifier resolves to that package'sexportssourcetarget (orsrc/<subpath>). Relative and other imports resolve as StyleX's do. Canonical names follow StyleX's own rule, so core's classes don't change.commonJSresolution wherever workspace source is compiled against another package's.stylexfiles: 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.stylexfiles relatively, which already resolve to source.test-buildruns the Chromium check below after it installs Chromium.Evidence
:where(.xy4seo4:hover *)against core'sx1odsvnm. In Chromium, a lab child styled off core's marker stays red when the core owner is hovered.x1odsvnm, and the child turns blue on hover.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
Testing
scripts/stylex-module-resolution.test.mjs, 15 cases:commonJSresolution (names differ) and with the shared one (they match);test-buildstep.ASTRYX_STYLEX_BROWSER=1 … stylex-module-resolution.browser.test.mjs: passes; fails with lab's previous resolution (Received: "rgb(255, 0, 0)").pnpm build, thendiff -rof the four packages'distagainstmain's build: identical. Storybook CSS md5 identical.pnpm -F @astryxdesign/storybook typecheck: passes; the.d.ctstypes the resolution as StyleX's own customModuleResolution(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.