Skip to content
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

feat: better dev theme names #803

Merged
merged 13 commits into from
Dec 16, 2024
Merged

feat: better dev theme names #803

merged 13 commits into from
Dec 16, 2024

Conversation

mellyeliu
Copy link
Member

@mellyeliu mellyeliu commented Dec 6, 2024

What changed / motivation ?

Let's modify the themeNameHash in debug mode to include the key before the hash like so:

  • key-themeHash

Tests

Added a basic test to cover theme names when debug is on

Pre-flight checklist

@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 Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

workflow: benchmarks/size

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

@stylexjs/[email protected] size:compare
./size-compare.js /tmp/tmp.qzWeiBmPjv /tmp/tmp.ztSKSvp2js

Results Base Patch Ratio
stylex/lib/stylex.js
· compressed 729 729 1.00
· minified 2,541 2,541 1.00
stylex/lib/StyleXSheet.js
· compressed 1,266 1,266 1.00
· minified 3,776 3,776 1.00
rollup-example/.build/bundle.js
· compressed 567,110 567,110 1.00
· minified 10,232,512 10,232,512 1.00
rollup-example/.build/stylex.css
· compressed 100,626 100,626 1.00
· minified 757,176 757,176 1.00

} = objMap(variables, (value, key) => {
// Created hashed variable names with fileName//themeName//key

const processedKey = key.startsWith('--') ? key.slice(2) : key;
const themeNamePrefix = debug ? `${processedKey}` : '';
Copy link
Member Author

Choose a reason for hiding this comment

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

let's sync on what we want to prefix here, I'm putting processedKey as a placeholder but can be modified to be themeName-processedKey etc. I noticed in the testing that some of the themeNames include special characters beyond alphanumeric and dash symbols, which could potentially break things, so it'd be good to validate

Copy link
Contributor

Choose a reason for hiding this comment

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

If the key starts with -- don't add a prefix at all. In those cases we don't generate a variable name and use the key name as is.

"rtl": null,
},
"bgColorDisabled-x568ih9-kpd015": {
"ltr": "@supports (color: oklab(0 0 0)){:root, .bgColorDisabled-x568ih9{--xpegid5:oklab(0.7 -0.3 -0.4);}}",
Copy link
Contributor

@necolas necolas Dec 6, 2024

Choose a reason for hiding this comment

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

Is this output correct? It looks like the source is a "supports" nested in a "media" for dark mode, but the output is missing the media part.

It's a little difficult to read the test because there are several patterns in the input and a lot of generated content as a result. It might be worth breaking it up so it's easier to check the output by eye

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, --xpegid5: doesn't have the prefix.

Instead the className that defines the variables has the prefix which is likely wrong.

@mellyeliu mellyeliu changed the title [feat] better dev theme names feat: better dev theme names Dec 6, 2024
@mellyeliu
Copy link
Member Author

updated to prefix the variable names with key as discussed with @nmn

@mellyeliu mellyeliu marked this pull request as ready for review December 13, 2024 22:16
Copy link
Contributor

@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.

I think there's only a bug in the test. The code changes look good.

@nmn nmn merged commit a21e739 into main Dec 16, 2024
8 checks passed
@nmn nmn deleted the cli-cache branch December 16, 2024 21:02
aminaopio pushed a commit to aminaopio/stylex that referenced this pull request Dec 22, 2024
* prefix dev classnames with property name
* added debug config and babel tests
* add caching to default path
aminaopio pushed a commit to aminaopio/stylex that referenced this pull request Dec 22, 2024
* prefix dev classnames with property name
* added debug config and babel tests
* add caching to default path
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