Skip to content

fix(build): resolve defineConsts read across files in astryxStylex - #8075

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:build/stylex-defineconsts
Oct 31, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:build/stylex-defineconsts

Conversation

@vjeux

@vjeux vjeux commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

User impact

Source builds through astryxStylex (Storybook's too) lose defineConsts values read from another file: a media-query key fails the build ("Invalid empty selector"); a value ships var(--x…) that nothing declares, which browsers drop. Plain @stylexjs/unplugin resolves both.

Problem and solution fit

StyleX compiles a constant read to a placeholder, var(--<prefix><hash>), that the final CSS pass replaces. Two defects break that:

  • Missing import compensation. Under the {stylexOptions} form, the babel wrapper's StyleX instance runs without treeshakeCompensation, so the TypeScript transform drops the now-unused import and the defining module never loads.
  • Per-layer, per-prefix substitution. A constant defined across the layer split, or in a package (library prefix) and read by an app (product prefix), stays a placeholder.

Fix:

  • The wrapper defaults to treeshakeCompensation: true, as the unplugin does.
  • Every layer gets every constant under every prefix; constant rules emit no CSS.
  • A production build warns, naming the property and its rule, when its stylesheet reads a generated property no emitted stylesheet declares. No record admits an astryxStylex option for it, so there is none.

Expected behavior and authority

StyleX inlines defineConsts values where used, media-query keys included, as @stylexjs/unplugin does. The prebuilt stylesheets already fail on the condition the warning reports.

Smallest restoration

packages/build/src/vite.ts, with the detector in internal undefinedVariables.ts (./vite exports only astryxStylex and LIGHTNINGCSS_TARGETS); an explicit treeshakeCompensation still wins.

Evidence

  • Before: the new stylex-consts fixture (sibling, cross-layer and package constants as keys and values) fails the legacy form ("Invalid empty selector"); the zero-config form ships placeholders.
  • After: both forms emit min-height:52px, padding-top:13px, padding-bottom:17px and both media rules.
  • Unchanged: the Storybook build on main and with this change is byte-identical (astryx-stylex-9dbf4f45.css) and passes the check.
  • Regression tests: both forms; cross-layer and cross-prefix reads; a plain export read as a token warns; a custom classNamePrefix; an app's own --xl/--xlarge isn't reported. Open siblings perf(i18n): let a component carry only its own English strings #7357 and perf(i18n): every core component renders with its own English slice #7358 also change vite.ts; both merge with this change without a conflict there.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. The warning has its own [feat] changeset and adds no option.
  • Public text and artifacts contain no internal Meta context.

Testing

  • Local gates at 8f66f86: build, type check, pnpm test:ui (16,446), the node suites, lint, Storybook, pnpm check:knowledge and changeset coverage.
  • pnpm exec vitest run packages/build scripts/build-css apps/storybook/.storybook/main.test.ts: 161 passed, 6 skipped (browser-only). This includes the new build tests (both forms, cross-layer, cross-prefix, the warning, a custom product prefix, an app's own properties) and the detector unit tests; each new test fails without the change.
  • pnpm -F @astryxdesign/build build; tsc -p packages/build/tsconfig.build.json --noEmit.
  • Changeset coverage: ships to @astryxdesign/build, two changesets ([fix] for the correction, [feat] for the warning); pnpm check:changesets passes.
  • pnpm storybook:build on main and with this change: identical StyleX CSS (astryx-stylex-9dbf4f45.css), and the check reports nothing. pnpm -F @astryxdesign/sandbox build: no report either.

@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 30, 2026 10:23pm UTC

Request Review

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Oct 24, 2026
@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 30, 2026, 10:48 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 24, 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 defineConsts restoration (the legacy form's treeshakeCompensation default and constants shared across layers) is well covered by the new build tests, but approval waits on a decision about the new public undefinedVariables: 'warn' | 'error' option and its default production-build warning, which no current spec covers. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, or by naming the spec that governs it; the author can do so as an engineering owner.

  • Either way, keep undefinedGeneratedVariables internal: exported from @astryxdesign/build/vite, it would ship as public API.
  • Either way, with the default astryx/x prefixes a product reading an Astryx package's constants still gets var(--x…), so re-key shared constants per prefix or narrow the changeset's claim.
  • If the option stays, the check must stop reporting a product's own var(--xl) (declared in its app CSS) as a dropped declaration, which also fails that build under 'error'.
  • If the option stays, honour stylexOverrides.classNamePrefix in the zero-config check and declare the option in a [feat] changeset.

[Automated review]

Comment thread packages/build/src/vite.ts Outdated
libraryLayer,
productLayer,
lightningcssOptions: stylexOptions.lightningcssOptions,
classNamePrefixes: [stylexPrefix, 'x'],

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 zero-config form compiles product files with stylexOverrides.classNamePrefix when it is set, but this checks only 'x', so with classNamePrefix: 'app' an undeclared --app… read is never reported. stylexOverrides.classNamePrefix ?? 'x' would match what the legacy form does at lines 807-811.

Comment thread packages/build/src/vite.ts Outdated
* SYNC: scripts/build-css.mjs `undefinedStyleXVariables` is the same check
* for the prebuilt package stylesheets.
*/
export function undefinedGeneratedVariables(

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.

Exporting this from the ./vite entry ships it in dist/vite.mjs and dist/vite.d.ts as public API of @astryxdesign/build/vite. Since it exists for the unit tests, consider moving it to a module the entry does not re-export and testing it there.

Comment thread packages/build/src/vite.ts Outdated
const read = new Set(
[
...css.matchAll(
new RegExp(`var\\(\\s*(--(?:${names})[a-z0-9]+)\\s*[,)]`, '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.

Every var(--x[a-z0-9]+) read counts as generated and only this stylesheet's declarations count as declared, so a product style reading its own var(--xl) (declared in its app CSS) is reported as a declaration every browser drops, and fails the build under 'error'. Counting declarations from every emitted stylesheet and reporting only hash-shaped names would avoid that.

'@astryxdesign/build': patch
---

[fix] `astryxStylex` resolves `defineConsts` values read from another file. With the `{stylexOptions}` form (the one Storybook uses), a file that read only constants from a `.stylex.ts` module lost that import once StyleX compiled it, so the constants never reached the CSS: a constant used as a media-query key failed the build ("Invalid empty selector") and one used as a value shipped as a custom property nothing declares. A constant defined on the library side of the layer split and read on the product side stayed unresolved in either form. A production build now also warns, naming the variable and the rule that reads it, when its stylesheet reads a StyleX-generated custom property that nothing declares; set `undefinedVariables: 'error'` to fail the build instead.

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.

With the default prefixes (Astryx package files astryx, product files x), a product reading an Astryx package's constant still builds to var(--x…): StyleX keys the reader's placeholder with the reader's prefix, so sharing constants across layers only resolves same-prefix pairs. Either re-key shared constants per prefix or narrow this sentence; the new option also reads as a [feat] rather than part of this [fix].

@github-actions

github-actions Bot commented Oct 24, 2026 •

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: The accessibility audit did not run on this pull request. It runs after merges to main and before each release; pull requests that touch components run it with the ci:heavy-lanes label.


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

@cixzhang

Copy link
Copy Markdown
Contributor

Posted by Cindy's agent on her behalf.

Parts of this PR re-implement behavior that already exists, or is being specified, as a shared part of core. Converging keeps one implementation per behavior:

  • Touch gating. build/__fixtures__/stylex-consts/appConsts.stylex.ts:7 writes its own (pointer: coarse) check. This conflicts with AST-012 FR2 (touch is resolved once, through the closed adaptation vocabulary) and public-component-api INV16. Resolve through the shared touch resolver key so behavior matches the spec. If this behavior genuinely can't be expressed through the resolver, please raise it here as a spec question instead of shipping a separate check.

This is about where the behavior lives, not about the PR's intent.

@vjeux

vjeux commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Agreed: the fixture should not gate touch itself. In 0268a58, appConsts.stylex.ts keys on @media (max-width: 599px) instead of (pointer: coarse), and the build test asserts that width rule; the fixture still proves that a defineConsts value read from another file works as a media-query key, and touch stays with the shared resolver (its constants will be read the same way once they are exported).

@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 legacy form's treeshakeCompensation default and the constants shared across layers fix the reported defineConsts failures, but approval waits on a decision about the new public undefinedVariables: 'warn' | 'error' option and its default production-build warning, which no current spec covers. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, or by naming the spec that governs it; the author can do so as an engineering owner.

  • Either way, keep undefinedGeneratedVariables internal: exported from @astryxdesign/build/vite, it would ship as public API.
  • Either way, with the default astryx/x prefixes a product reading an Astryx package's constants still gets var(--x…), so re-key shared constants per prefix or narrow the changeset's claim.
  • If the option stays, the check must stop reporting a product's own var(--xl) (declared in its app CSS) as a dropped declaration, which also fails that build under 'error'.
  • If the option stays, honour stylexOverrides.classNamePrefix in the zero-config check and declare the option in a [feat] changeset.

[Automated review]

@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 treeshakeCompensation default and the shared constant rules fix the reported defineConsts failures, but approval waits on a decision about the new public undefinedVariables: 'warn' | 'error' option and its default production-build warning, which no current spec covers. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, or by naming the spec that governs it; the author can do so as an engineering owner.

  • Either way, keep undefinedGeneratedVariables internal: exported from @astryxdesign/build/vite, it ships as public API.
  • Either way, with the default astryx/x prefixes a product reading an Astryx package's constant still builds to var(--x…), so narrow the [fix] changeset's library-side sentence or re-key shared constants for each prefix.
  • If the option stays, stop reporting a product's own var(--xl) (declared in its app CSS) as a dropped declaration, and honour stylexOverrides.classNamePrefix in the zero-config check.

[Automated review]

vjeux added a commit to vjeux/astryx that referenced this pull request Oct 25, 2026
Source builds through astryxStylex (Storybook's too) lost defineConsts
values read from another file: a media-query key failed the build
("Invalid empty selector"), and a value shipped var(--x…) that nothing
declares, which browsers drop. The babel wrapper now defaults to
treeshakeCompensation, as @stylexjs/unplugin does, so the defining module
still loads, and every layer gets every constant under every class-name
prefix, with constant rules emitting no CSS. A production build warns,
naming the property and its rule, when its stylesheet reads a generated
property no emitted stylesheet declares (internal undefinedVariables.ts,
with no option); the prebuilt stylesheets' check reads the same
hash-shaped names.

@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 changes requested: the defineConsts restoration holds up, with sibling, library-side and package constants now resolving in both astryxStylex forms and Storybook's StyleX stylesheet unchanged byte for byte. The new build tests fail without the change and pass here. The always-on production-build warning has no spec record, and the engineering owners' choice of that behaviour, cited in the reply on this thread, settles it. Nothing further is needed from the author.

[Automated review]

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Oct 31, 2026
@cixzhang
cixzhang marked this pull request as ready for review October 31, 2026 01:50
cixzhang pushed a commit that referenced this pull request Oct 31, 2026
…mator (#8076)

Behavior-module PR: internal touch foundation, animator, press tracking

Stacked on #8071, one commit on `main`, with no merge commits: review only this pull request's two commits, vjeux@0ddfa8937e and its test vjeux@91d49e1438.

## Why

Touch components need Core's animator, press tracking and gesture host without making them public.

## What it absorbs, and why

One solution, the internal touch foundation, so these close with a link here:

- #8073 (closed): UIControl press tracking, its press profiles and the hooks. Everything else here rests on it.
- #8340: the animator's start and hold. No frame shows where a motion is going, a call can wait for a presented frame, and in Safari a start from rest moves past a block of over two frames in the task that created it. It brings the held dip's load fixes from #8360 too.
- #8641's rule (approved): a gesture that cancels itself while its finger moves keeps that finger until it lifts.

## Left out

- Nothing here rests on the undecided mouse or pen drag selection (#8665), wheel ending (#8676) or an open owner ruling.
- #8446's harness changes land with #8554.
- The StyleX `defineConsts` build fix and the stylesheet's undefined-variable check stay in #8075.
- `RotationGestureRecognizer` and `HoverGestureRecognizer` are not exported: nothing uses them, and rotation's threshold is not measured.
- `paintPress` and its held state land with the action-group tracker, `useAnimator` with Lab's SearchField, and Core's internal entry points for Lab (#8562's change) with the first Lab component that uses them: each with its first user.

## What changes

- Press tracking follows UIControl and is built by `createPressTracker`: the press clocks and profiles, `usePressTracker`, and release velocity on UIKit's filter (`spec:AST-100` FR1, FR2).
- The animator holds the value on screen inline while a curve runs, starts a motion from rest when the browser commits it, offers `start: 'presented'` and `'commit'`, additive reversals and `handle.curve`. A browser proof counts no Layout or Paint while a spring plays, on the harness's rendering trace.
- The motion modules and recognizers load in plain Node, with no StyleX module in their graph.

## How to check it

1. Run `pnpm exec vitest run scripts/motion-node-load.test.mjs`: the motion modules and recognizers load in a plain Node process.
2. In a component using `usePressTracker`, change `highlightDelay` while mounted: the next touch uses the new delay.
3. Run `pnpm test:interaction animator.interaction.browser.spec.ts` in Chromium and WebKit: a motion started right before a blocked main thread plays from its start after the block.

## Evidence

- Local gates at 91d49e1: build, type check, `pnpm test:ui` (16,704), the node suites, lint, Storybook, and the motion and gesture interaction specs in Chromium (103) and WebKit (96); the held-dip, block and no-Layout-or-Paint proofs pass six times each at eight workers.

## Credit

Co-authored-by: Cindy Zhang (her commits in #8073 and #8076).

## Scope

- [x] Unrelated fixes, cleanup, and policy changes were removed or split.
- [x] Public text and artifacts contain no internal Meta context.



Behavior-module PR: LOC split waived per maintainer rule.
@cixzhang
cixzhang merged commit 8d0a847 into meta:main Oct 31, 2026
141 of 143 checks passed
@vjeux
vjeux deleted the build/stylex-defineconsts branch October 31, 2026 06:05
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
…eset; current main) into the touch foundation
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
…eck reads the build's own CSS) into the touch foundation
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
… declares) into the touch foundation

CI-Rerun: main's gate test (fixed in meta#8406) failed this head's test-node
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
…t as the build does) into the touch foundation
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
… into meta#8320

- Pan: meta#8060's FR14 removal of the scroll-edge handoff, with this line's
  opt-in early claim ('early', from the table) and its committed claim
  that survives a second finger; meta#8076's default-on copy of that test goes.
- The UIKit table takes meta#8053's form (value and unit, sources in JSDoc)
  and keeps earlyClaimDistance in it, dated.
- usePressTracker stays in its own module here.
- The README's pan row keeps scrollVelocity() and loses scrollHandoff.
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026
… into meta#8293

The motion README keeps the presentation row beside the animator's new
wording; the animator test imports the coast and the presentation reads.
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 3, 2026

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) 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.

2 participants