styled-components: v2.1 Missing media queries with SSR
In 2.1.0 (compared to 2.0.0), some of my media queries have broken in production. Something simple like below doesn’t trigger and I get no error. It looks like it’s just missing from the CSS.
@media (min-width: ${breakpoints.sm}) {
width: ${imageSizeLg};
height: ${imageSizeLg};
}
I’m using Gatsby, so production meaning SSR. This is the code integrating styled-components
What I find strange is that there are still media query statements in the generated CSS, even ones that are using the exact same query.
Any idea what might have caused this?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 21 (12 by maintainers)
I was able to reproduce this:
The relevant part being:
But I was only able to reproduce it using
preprocessturned on in the babel plugin. So at least @Cinamonas reproduction is only a configuration mistake. Do note thatpreprocessis experimental and just a test leading up to v3, if you’ve purposefully turned it on 😉I’m also sure that this triggers @0x80 bug, due to an edge-case in the preprocessing:
The preprocessing maps over the first level of arrays (the second being for the interpolations) and prepends each of them with the classname. When we use a media query, the first set of rules is not supposed to have a classname prepended to it (duh), so it fails. If you do want to continue using the experimental preprocessing, just put a dummy rule in front of the media query.
Btw before being done here, coming back to the first reproduction I mentioned:
This will never work with preprocessing, as we can’t preprocess dynamic input. The correct usage with it would be:
I hope this explains the issue 😉
Ooh sounds like a result! I’ll leave this to @philpl hopefully we can cut a new release of the parser and we’ll be golden.