Repository navigation
feat: add example-nextjs-source with split-layer StyleX plugin - #1421
Merged
Merged
Conversation
New source build example that compiles @xds/core from raw TypeScript + StyleX source alongside product code. A custom PostCSS plugin (stylex-split-layers.js) partitions compiled StyleX rules by file path and wraps them in separate CSS layers: reset < xds-base (library) < xds-theme < product (app) This ensures product StyleX styles always override XDS component defaults without !important or specificity hacks. Includes a layer demo showing the three-layer cascade on buttons: base default → theme override → product override.
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
Move the custom PostCSS plugin from a local file in the example app to a proper package at packages/postcss-plugin. This is a dev dependency that source-build consumers install alongside @xds/core. The example app's postcss.config.js now references '@xds/postcss-plugin' instead of './stylex-split-layers'.
cixzhang
commented
Apr 16, 2026
Comment on lines
+194
to
+203
| const libraryCss = libraryRules.length | ||
| ? stylexBabelPlugin.processStylexRules(libraryRules, { | ||
| useLayers: true, | ||
| }) | ||
| : ''; | ||
| const productCss = productRules.length | ||
| ? stylexBabelPlugin.processStylexRules(productRules, { | ||
| useLayers: true, | ||
| }) | ||
| : ''; |
Contributor
Author
There was a problem hiding this comment.
@mellyeliu -- is it going to be okay for us to use stylex's babel plugin this way?
Reduce config to two required options:
- appDir: where your app source lives (default: 'src')
- babelPlugins: your StyleX babel plugins
The plugin handles XDS-specific defaults internally:
- Auto-includes node_modules/@xds/**/*.{ts,tsx}
- Knows its own library pattern for layer splitting
- Configures TypeScript/JSX parsing
- Uses @stylexjs/stylex as the import source
Before:
include: ['src/**/*', 'node_modules/@xds/core/**/*'],
babelConfig: { babelrc: false, parserOpts: {...}, plugins: ... },
libraryPattern: 'node_modules/@xds/',
After:
appDir: 'src',
babelPlugins: babelConfig.plugins,
cixzhang
added a commit
that referenced
this pull request
Apr 26, 2026
* feat: add example-nextjs-source with split-layer StyleX plugin
New source build example that compiles @xds/core from raw TypeScript +
StyleX source alongside product code. A custom PostCSS plugin
(stylex-split-layers.js) partitions compiled StyleX rules by file path
and wraps them in separate CSS layers:
reset < xds-base (library) < xds-theme < product (app)
This ensures product StyleX styles always override XDS component
defaults without !important or specificity hacks.
Includes a layer demo showing the three-layer cascade on buttons:
base default → theme override → product override.
* docs: explain why layers.css is a separate file
* refactor: extract stylex-split-layers into @xds/postcss-plugin package
Move the custom PostCSS plugin from a local file in the example app
to a proper package at packages/postcss-plugin. This is a dev
dependency that source-build consumers install alongside @xds/core.
The example app's postcss.config.js now references '@xds/postcss-plugin'
instead of './stylex-split-layers'.
* refactor: simplify @xds/postcss-plugin API
Reduce config to two required options:
- appDir: where your app source lives (default: 'src')
- babelPlugins: your StyleX babel plugins
The plugin handles XDS-specific defaults internally:
- Auto-includes node_modules/@xds/**/*.{ts,tsx}
- Knows its own library pattern for layer splitting
- Configures TypeScript/JSX parsing
- Uses @stylexjs/stylex as the import source
Before:
include: ['src/**/*', 'node_modules/@xds/core/**/*'],
babelConfig: { babelrc: false, parserOpts: {...}, plugins: ... },
libraryPattern: 'node_modules/@xds/',
After:
appDir: 'src',
babelPlugins: babelConfig.plugins,
cixzhang
added a commit
that referenced
this pull request
Jun 21, 2026
* feat: add example-nextjs-source with split-layer StyleX plugin
New source build example that compiles @xds/core from raw TypeScript +
StyleX source alongside product code. A custom PostCSS plugin
(stylex-split-layers.js) partitions compiled StyleX rules by file path
and wraps them in separate CSS layers:
reset < xds-base (library) < xds-theme < product (app)
This ensures product StyleX styles always override XDS component
defaults without !important or specificity hacks.
Includes a layer demo showing the three-layer cascade on buttons:
base default → theme override → product override.
* docs: explain why layers.css is a separate file
* refactor: extract stylex-split-layers into @xds/postcss-plugin package
Move the custom PostCSS plugin from a local file in the example app
to a proper package at packages/postcss-plugin. This is a dev
dependency that source-build consumers install alongside @xds/core.
The example app's postcss.config.js now references '@xds/postcss-plugin'
instead of './stylex-split-layers'.
* refactor: simplify @xds/postcss-plugin API
Reduce config to two required options:
- appDir: where your app source lives (default: 'src')
- babelPlugins: your StyleX babel plugins
The plugin handles XDS-specific defaults internally:
- Auto-includes node_modules/@xds/**/*.{ts,tsx}
- Knows its own library pattern for layer splitting
- Configures TypeScript/JSX parsing
- Uses @stylexjs/stylex as the import source
Before:
include: ['src/**/*', 'node_modules/@xds/core/**/*'],
babelConfig: { babelrc: false, parserOpts: {...}, plugins: ... },
libraryPattern: 'node_modules/@xds/',
After:
appDir: 'src',
babelPlugins: babelConfig.plugins,
cixzhang
added a commit
that referenced
this pull request
Jun 21, 2026
* feat: add example-nextjs-source with split-layer StyleX plugin
New source build example that compiles @xds/core from raw TypeScript +
StyleX source alongside product code. A custom PostCSS plugin
(stylex-split-layers.js) partitions compiled StyleX rules by file path
and wraps them in separate CSS layers:
reset < xds-base (library) < xds-theme < product (app)
This ensures product StyleX styles always override XDS component
defaults without !important or specificity hacks.
Includes a layer demo showing the three-layer cascade on buttons:
base default → theme override → product override.
* docs: explain why layers.css is a separate file
* refactor: extract stylex-split-layers into @xds/postcss-plugin package
Move the custom PostCSS plugin from a local file in the example app
to a proper package at packages/postcss-plugin. This is a dev
dependency that source-build consumers install alongside @xds/core.
The example app's postcss.config.js now references '@xds/postcss-plugin'
instead of './stylex-split-layers'.
* refactor: simplify @xds/postcss-plugin API
Reduce config to two required options:
- appDir: where your app source lives (default: 'src')
- babelPlugins: your StyleX babel plugins
The plugin handles XDS-specific defaults internally:
- Auto-includes node_modules/@xds/**/*.{ts,tsx}
- Knows its own library pattern for layer splitting
- Configures TypeScript/JSX parsing
- Uses @stylexjs/stylex as the import source
Before:
include: ['src/**/*', 'node_modules/@xds/core/**/*'],
babelConfig: { babelrc: false, parserOpts: {...}, plugins: ... },
libraryPattern: 'node_modules/@xds/',
After:
appDir: 'src',
babelPlugins: babelConfig.plugins,
4 tasks done
cixzhang
pushed a commit
that referenced
this pull request
Oct 21, 2026
…ibrary pass (#7774) <!-- template: bug-fix.md --> ## User impact Every documented Next.js source build pays for an unused Babel run over every installed Astryx module. `@astryxdesign/build`'s PostCSS plugin compiles Astryx source to collect its StyleX rules with `babelrc: false` but not `configFile: false`, so Babel also loads the app's root `babel.config.js`: in the documented setup, `next/babel` plus Astryx's StyleX plugin. The CSS pass then runs preset-env, Next's plugins and a second StyleX instance over package source, only to read StyleX metadata. On a clean install of the documented example that roughly doubles the pass, for byte-identical CSS. ## Problem and solution fit - Why it happens: `babelrc: false` only disables `.babelrc` files; Babel still loads a root config file unless told `configFile: false`. - Why it harms: the extra transforms produce nothing the pass uses, and they scale with the Astryx packages installed, not used. - Why that matters: the app cannot keep its root config out of the plugin's pass without dropping it from its own compile. ## Expected behavior and authority No record governs the plugin's build cost. `spec:AST-080` FR7 (current) governs its output, which stays byte-identical. The pass already opts out of the app's Babel configuration with `babelrc: false` (since #1421); `configFile: false` extends that to the root config file Babel also loads. #5464 shows the same leak failing a consumer's StyleX pass. ## Smallest restoration - The library pass sets `configFile: false`; it already passes its own parser options and plugins. - The app's own files still compile with its config, which may carry syntax plugins they need. ## Evidence - Reproduction before the change: on a clean registry install of the documented example, the app's PostCSS config takes a median 37.4 s with the README's browserslist and 67.3 s with none (5 fresh-process runs each, alternating order; the no-browserslist case has #7767 applied, since main does not build without one). - Result after the change: 20.3 s and 21.4 s, with byte-identical CSS across all 20 runs. - Representative unchanged path: the app's own files still compile with its config, which the test asserts. - Regression test or other mutation-sensitive proof: `postcss.test.mjs` runs the documented config from an app whose `babel.config.js` records each file it is applied to. On main it records the Astryx module; here only the app's. ## Scope - [x] One defect is restored. - [x] Separable contradictory or unsettled tagalongs were removed or split. - [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. - [x] Public text and artifacts contain no internal Meta context. ## Testing - `pnpm exec vitest run --project node packages/build`: 6 files, 79 tests pass; `postcss.test.mjs` fails on main. - CSS-pass runs, before and after: README browserslist 35.7/41.1/36.7/37.4/38.1 s and 19.9/24.8/20.3/20.0/22.8 s; none 67.3/75.8/67.8/65.9/52.9 s and 19.9/21.4/24.9/24.7/19.7 s. - `pnpm -F @astryxdesign/core typecheck`, Prettier, `pnpm check:repo`, changeset coverage: pass (ESLint ignores `packages/build/src`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New source build example for serious consumers who want an optimized production build. Compiles
@xds/corefrom raw TypeScript + StyleX source alongside product code in a single build pass — fully tree-shaken, zero unused CSS.Split-layer PostCSS plugin
The key innovation is
stylex-split-layers.js— a custom PostCSS plugin that wraps the StyleX compilation and partitions the output by source file path:node_modules/@xds/) →@layer xds-basesrc/) →@layer productCombined with
reset.cssandtheme.css, the full cascade is:Product StyleX styles always override XDS component defaults and theme overrides without
!importantor specificity hacks.Layer demo
Includes a visual demo showing the three-layer cascade on buttons:
Example apps matrix
example-nextjsexample-nextjs-tailwindexample-nextjs-stylexexample-nextjs-source