Skip to content

Conversation

@mellyeliu
Copy link
Member

@mellyeliu mellyeliu commented Oct 20, 2025

Depending on the way users serve their CSS, you may want to declare a separate filepath for constants. For example, when using directory-based bundling, you'd need to include all constants files alongside each folder to have constants work globally.

This PR adds a .const appended variant to the suffix defined in themeFileExtension (.stylex.js by default) so packagers can statically analyze which files contain constants. I considered making this configurable like themeFileExtension, but decided to keep this hardcoded for now for simplicity.

As a follow up, we should update the enforce-extension lint rule to handle defineConsts under the new extension, with a config to allow users to hard enforce the .stylex.const.js extension (ie. no defineConsts in the default theme extension). The default behaviour will be that both .stylex.js and .stylex.const.js will be considered valid extensions for files declaring defineConsts exports.

Also contains a fix to valid-styles to respect user configured themeFileExtension

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 20, 2025
@github-actions
Copy link

github-actions bot commented Oct 20, 2025

workflow: benchmarks/perf

Comparison of performance test results, measured in operations per second. Larger is better.

benchmarks@0.16.2 compare
node ./compare.js /tmp/tmp.bfL65E3LAH /tmp/tmp.cSugXcjPYP

Results Base Patch Ratio
babel-plugin: stylex.create
· basic create 638 647 1.01 +
· complex create 193 188 0.97 -
babel-plugin: stylex.createTheme
· basic themes 464 460 0.99 -
· complex themes 44 43 0.98 -
@github-actions
Copy link

github-actions bot commented Oct 20, 2025

workflow: benchmarks/size

Comparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.

benchmarks@0.16.2 compare
node ./compare.js /tmp/tmp.X3Sd1zduTu /tmp/tmp.N0HUw7bOjv

Results Base Patch Ratio
@stylexjs/stylex/lib/cjs/stylex.js
· compressed 1,278 1,278 1.00
· minified 3,986 3,986 1.00
@stylexjs/stylex/lib/cjs/inject.js
· compressed 1,223 1,223 1.00
· minified 3,216 3,216 1.00
benchmarks/size/.build/bundle.js
· compressed 496,650 496,650 1.00
· minified 4,847,840 4,847,840 1.00
benchmarks/size/.build/stylex.css
· compressed 99,853 99,853 1.00
· minified 747,541 747,541 1.00
@mellyeliu mellyeliu marked this pull request as ready for review October 20, 2025 22:29
@mellyeliu mellyeliu marked this pull request as draft October 21, 2025 04:29
@mellyeliu
Copy link
Member Author

Tested on example-nextJS for safety;

Compiler error with

import { tokens } from './ConstantTokens.stylex.constss';

Resolves correctly with

import { tokens } from './ConstantTokens.stylex.const';
@mellyeliu mellyeliu merged commit 922b6d2 into main Oct 22, 2025
9 checks passed
@mellyeliu mellyeliu deleted the defineConsts-file branch October 22, 2025 06:12
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 Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

4 participants