v2.1 Missing media queries with SSR
See original GitHub issueIn 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?
Issue Analytics
- State:
- Created 6 years ago
- Comments:21 (12 by maintainers)
Top Results From Across the Web
NextJs SSR not recognizing CSS Media queries for mobile
I just integrated Nextjs SSR into my React project. Before this, my css media queries for mobile-responsiveness were working perfectly.
Read more >POC Next SSR media queries - React.js Examples
An experiment and evaluation of different strategies to handle media queries when doing SSR. Jan 01, 2022 6 min read.
Read more >Blog Js Media Queries | janosh.dev
JS media queries with React hooks ... This post assumes you're using React (16.8 or later). One thing I like about styled-components is...
Read more >Media queries in React for responsive design - Material UI - MUI
This is a CSS media query hook for React. It listens for matches to a CSS media query. It allows the rendering of...
Read more >Keeping Server-Side Rendering Cool With React Hydration
What is Server-Side Rendering (SSR)?; What is Client-Side Rendering ... 1. Missing Data on Server-Side. Something helpful to keep in mind is ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to reproduce this:
The relevant part being:
But I was only able to reproduce it using
preprocess
turned on in the babel plugin. So at least @Cinamonas reproduction is only a configuration mistake. Do note thatpreprocess
is 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.