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

fix: add inline processing for borderWidth, borderColor, borderStyle to valid-shorthands #817

Merged
merged 4 commits into from
Dec 20, 2024

Conversation

mellyeliu
Copy link
Member

Context

When using the preferInline config, we were expanding margin/padding to equivalent inline logical properties. However, we overlooked applying the same transform to certain border properties.

The change introduced here extends the inline logical transformation to border properties (specifically borderWidth, borderStyle, and borderColor) by applying the same logic used for margin and padding. We take the output from css-shorthand-expand and apply a transform to the physical properties returned.

Testing

Added test expansions for borderWidth, borderStyle, and borderColor with preferInline set to default (false) and true

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 20, 2024
@mellyeliu mellyeliu requested review from nmn and necolas December 20, 2024 16:31
Copy link

github-actions bot commented Dec 20, 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.MBxhOCjb3a /tmp/tmp.WgVtxIO6hd

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

const directionalProperties = [
'border-width',
'border-color',
'border-style',
Copy link
Contributor

Choose a reason for hiding this comment

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

We should include borderRadius too. Is there anything else? Where is the configuration for enabling this for padding and margin located? Do we know if OSS users get consistent behavior across properties (it should default for physical properties for every shorthand)

Copy link
Member Author

@mellyeliu mellyeliu Dec 20, 2024

Choose a reason for hiding this comment

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

These are the supported properties, I believe it's just these that are directional:

borderColor
borderWidth
borderStyle
borderRadius
margin
padding
marginBlock
marginInline
paddingBlock
paddingInline

And these that are left as is: (ie. we won't modify anything existing with physical properties, just expand them as is)
borderTop
borderRight
borderBottom
borderLeft
background
font
outline

There's a global config preferInline that's set when configuring the lint rule; it's default false for all properties, so by default all properties use physical properties when this config is not set.

@mellyeliu mellyeliu merged commit 7f545cf into main Dec 20, 2024
8 checks passed
@mellyeliu mellyeliu deleted the shorthands-border branch December 20, 2024 18:47
aminaopio pushed a commit to aminaopio/stylex that referenced this pull request Dec 22, 2024
aminaopio pushed a commit to aminaopio/stylex that referenced this pull request Dec 22, 2024
aminaopio pushed a commit to aminaopio/stylex that referenced this pull request Dec 23, 2024
aminaopio pushed a commit to aminaopio/stylex that referenced this pull request Dec 27, 2024
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.

3 participants