8000 [babel-plugin] Fix theming in dev/debug mode by necolas · Pull Request #1101 · facebook/stylex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[babel-plugin] Fix theming in dev/debug mode #1101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged

Conversation

necolas
Copy link
Contributor
@necolas necolas commented Jun 17, 2025

This fixes a bug in StyleX theming caused by how evaluate-path works in dev/debug mode, which produced bad debug class names for createTheme calls.

@facebook-github-bot facebook-github-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 Jun 17, 2025
Copy link
github-actions bot commented Jun 17, 2025

workflow: benchmarks/perf

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

benchmarks@0.13.1 compare
node ./compare.js /tmp/tmp.21SYfyEplV /tmp/tmp.Wuv6DV7KUa

Results Base Patch Ratio
babel-plugin: stylex.create
· basic create 529 532 1.01 +
· complex create 195 187 0.96 -
babel-plugin: stylex.createTheme
· basic themes 458 449 0.98 -
· complex themes 42 42 1.00

Copy link
github-actions bot commented Jun 17, 2025

workflow: benchmarks/size

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

benchmarks@0.13.1 compare
node ./compare.js /tmp/tmp.FzXbr8BuPh /tmp/tmp.sEXjs0F5dR

Results Base Patch Ratio
@stylexjs/stylex/lib/cjs/stylex.js
· compressed 1,222 1,222 1.00
· minified 3,679 3,679 1.00
@stylexjs/stylex/lib/cjs/inject.js
· compressed 1,227 1,227 1.00
· minified 3,224 3,224 1.00
benchmarks/size/.build/bundle.js
· compressed 537,611 537,611 1.00
· minified 7,435,904 7,435,904 1.00
benchmarks/size/.build/stylex.css
· compressed 100,509 100,509 1.00
· minified 754,513 8000 754,513 1.00

@mellyeliu

This comment was marked as outdated.

@necolas

This comment was marked as outdated.

@mellyeliu

This comment was marked as outdated.

@mellyeliu

This comment was marked as outdated.

nmn
nmn previously requested changes Jun 18, 2025
Copy link
Collaborator
@nmn nmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this seems to fix the "reactive variables" idea that many have, it has a major regression in how themes can be used and makes it impossible to have themes for separate varGroups managed separately.

"reactive variables" would also not quite work how people expect as it would only work on one comment at a time.

@necolas necolas force-pushed the babel-plugin/fix-theming branch from 15530d1 to 1a48787 Compare June 23, 2025 21:30
@necolas necolas changed the title [babel-plugin] Fix theming based on defineVars [babel-plugin] Fix theming in dev/debug mode Jun 23, 2025
@necolas necolas force-pushed the babel-plugin/fix-theming branch from 1a48787 to 84bd3bb Compare June 23, 2025 21:33
Comment on lines +88 to +91
{
[themeVars.__themeName__]: themeClass,
$$css: true,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change avoids the need for the flowfixme comment

Comment on lines +178 to +184
const varSafeKey =
key === '__themeName__'
? ''
: (key[0] >= '0' && key[0] <= '9' ? `_${key}` : key).replace(
/[^a-zA-Z0-9]/g,
'_',
) + '-';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix for dev/debug mode. The way theming is currently designed to work is broken in dev because this generates bad class names that don't map to anything in the generated CSS

@necolas necolas requested a review from nmn June 23, 2025 22:17
@mellyeliu
Copy link
Member

Dev/debug changes lgtm

This fixes a bug in StyleX theming. Before, defineVars was creating a
`:root` rule with a classname that is unique to a given defineVars call.
However, when debug mode is enabled, calls to createTheme were
generating bad debug class names and the unique classname for vars was
not being applied. This bug isn't caught by the unit tests because they
are using fixtures and not using the bad logic in evaluate-path.js
@necolas necolas force-pushed the babel-plugin/fix-theming branch from 84bd3bb to c5490c8 Compare June 23, 2025 22:42
@necolas necolas merged commit 643ee39 into main Jun 23, 2025
16 checks passed
@necolas necolas deleted the babel-plugin/fix-theming branch June 23, 2025 23:01
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0