Solving specificity in atoms and style arrays #333
Unanswered
Brendan-csel
asked this question in
Q&A
Replies: 1 comment 1 reply
-
The Sprinkles atoms function solves this by using an object based API. You can never set the same atom twice because objects don't allow duplicate keys. The last one always wins. Where Sprinkles can't help you is when combining Atoms with other class names. Vanilla-extract is a lower level system than stylex so it can't perform the same magic. In practice I don't see this as being a big issue though. I would suggest making your atoms the lowest precedence styles in your app (except for your reset) to avoid confusing CSS order scenarios. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After Mark's talk at React Finland there was an introduction to Stylex.
Stylex claims to resolve issues with css specificity while still using atomic css. This was questioned and the approach was explained during the question time.
Essentially it came down to expanding all the atoms out (so
paddingX
expanded topaddingLeft
andpaddingRight
), and then ensuring that only the class for the "last" value for each property was returned. I'm not sure if that would resolve the same property set with a shorthand versus explicit value though (eg. could it resolve a color fromborder
and eliminate conflict with a specificborderColor
property??).Does
atoms()
resolve duplicate properties already, or is it a possibility? Might it also be possible when composing styles using the new array api? (sounds impossible but had to ask)It sounds like it will be some time before Stylex comes out - and I'm not a fan of co-locating styles - but I can imagine the "usage order" approach to assist with the specificity challenge could become a desired expectation.
Beta Was this translation helpful? Give feedback.
All reactions