cxs-css / cxs

fast af css-in-js in 0.7kb
MIT License
1.19k stars 68 forks source link

Prevent ordering issues with media queries #56

Closed mihalik closed 7 years ago

mihalik commented 7 years ago

Fixes #47. See issue for discussions of other ways to solve the issue.

Due to how rules are rendered and cached in cxs, the ordering of rules for a specific element is nondeterministic. This is not a problem in most cases due to css specificity, but media queries don't increase specificity so the ordering is important. This PR enforces a specific ordering of media queries by always putting them into a second style block on the page.

This has a chance of being a breaking change if someone is relying on a media query to be included before the base rule. But, I think most people write their css with media rules at the end and the previous resolution was nondeterministic.

I have tested this in the example and my own application which has a number of media rules and everything works well. But, there might be a different usage pattern that I might have missed that would cause problems.

A few other notes:

gingur commented 7 years ago

+1

asilvas commented 7 years ago

+1

jxnblk commented 7 years ago

LGTM thanks!