stylex icon indicating copy to clipboard operation
stylex copied to clipboard

fix: conditional classes for dynamic styles for legacy expanded prope…

Open nmn opened this issue 1 year ago • 1 comments

Fixes for dynamic styles for expanded shorthands (when using "legacy-expand-shorthands")

Work so far

In the previous two PRs, I made it so that when using a dynamic style, if the dynamic value resolves to null or undefined, then:

  • Neither the inline style setting the CSS variable should be applied
  • Nor the className that uses that variable should be applied.

In order words, a dynamic style that resolves to null should behave just like a regular style that resolves to null.

What was fixed

Until the previous diff, when using styleResolution: 'legacy-expand-shorthands' any dynamic styles set to a shorthand were not correctly handled. This is because the keys in the original style object, the inline styles and the applied styles did not match.

This PR fixes that by re-using the same logic used to expand keys to also expand which keys we know are dynamic.

Also completed

~~We're not correctly adding px units for all properties that only take lengths and not numbers. Specifically, shorthand properties such as margin are not handled correctly. This will be fixed next.~~

  • [x] Done.

~~Also, once these PRs land, we can change the var(--prop-name, revert) to just var(--prop-name) as the static values used for dynamic styles.~~

  • [x] Done

nmn avatar Oct 07 '24 06:10 nmn

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.l3yBN3muHu /tmp/tmp.KIvZnKOrKP

Results Base Patch Ratio
stylex/lib/stylex.js
· compressed 899 899 1.00
· minified 3,223 3,223 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 563,025 563,025 1.00
· minified 10,185,368 10,185,368 1.00
rollup-example/.build/stylex.css
· compressed 99,154 99,154 1.00
· minified 745,649 745,649 1.00

github-actions[bot] avatar Oct 07 '24 06:10 github-actions[bot]