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

blog: designing for composition #716

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

nmn
Copy link
Contributor

@nmn nmn commented Oct 8, 2024

Blog Post

A blog post that describes how we arrived at certain API design decisions and how we
prioritise predictable style composition.

@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 Oct 8, 2024
Copy link

github-actions bot commented Oct 8, 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.4xob5pEibS /tmp/tmp.6DTzJeh34F

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,484 563,484 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

Copy link
Member

@mellyeliu mellyeliu left a comment

Choose a reason for hiding this comment

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

Some small styling nits and suggestions

now offer a way to merge styles.

Despite all the tools, style composition remains a challenge. From headless
UI libraries to design system components that are copied to your own codebase,
Copy link
Member

Choose a reason for hiding this comment

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

nit: double space

Suggested change
UI libraries to design system components that are copied to your own codebase,
UI libraries to design system components that are copied to your own codebase,

inline styles. To form a mental model, it can be helpful to think of StyleX
as "inline styles without the limitations".

StyleX gives you the ability to use capabilities such as pseudo classes and
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
StyleX gives you the ability to use capabilities such as pseudo classes and
StyleX allows you to use capabilities such as pseudo classes and

Comment on lines +81 to +83
By the time we made the conscious decision to model StyleX after inline styles,
StyleX had already been in development for a while and had evolved organically
inspired by React Native's `StyleSheet` API, which was itself inspired by inline
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
By the time we made the conscious decision to model StyleX after inline styles,
StyleX had already been in development for a while and had evolved organically
inspired by React Native's `StyleSheet` API, which was itself inspired by inline
By the time we made the conscious decision to model StyleX after inline styles,
StyleX had already been in development for a while, organically inspired by React Native's StyleSheet API—which itself was influenced by inline styles.

Comment on lines +160 to +164
React Native pioneered the approach of merging purely by key, and assigning
different priorities to different properties. Longhand properties have a higher
priority than shorthand properties. So, while you *can* end up
with a style object that has both `padding` and `paddingTop`, `paddingTop` will
take precedence regardless of the order in which they are applied.
Copy link
Member

Choose a reason for hiding this comment

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

should we define and use property specificity and application order here

we believe many of these tools need to exist entirely because of the inconsistencies
of merging styles.

We believe that we've built the first solution with style composition at its very core.
Copy link
Contributor

Choose a reason for hiding this comment

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

Meta engineering write ups typically focus on describing specific problems/opportunities we encounter, the root cause, how it was resolved, and the results seen. In that context, I think the voice and framing used throughout this draft could be revisited.

Another concern I have with this post is that one of the primary goals of StyleX was to optimize the output. One of the defaults doesn't do that, but discussing it in the post isn't particularly relevant to the main topic of the post.

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 very useful feedback! It helps me use a particular framing to do a second draft.


So, when it came to designing StyleX, we decided to model our styles after
inline styles. To form a mental model, it can be helpful to think of StyleX
as "inline styles without the limitations".
Copy link
Contributor

Choose a reason for hiding this comment

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

It does have limitations so this may be misleading

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