Dynamic global styles with SSR issue
See original GitHub issueCurrent behavior:
style tags generated by <Global />
components appear in front of style tags generated by SSR:
As a result, the dynamically calculated global styles cannot override the styles in the SSR:
To reproduce:
https://codesandbox.io/s/snowy-violet-tq704
Expected behavior:
The style generated by SSR should appear first:
Environment information:
react
version: 17@emotion/react
version: 11
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Implementing SSR in Next.js: Dynamic routing and prefetching
If you wanted to wrap the entire application in a component, perform some initialization operation, or include some global styles, then the _app ......
Read more >Server Side Rendering - Emotion
If you have dynamic global styles it's advised to create cache per single render to avoid global styles from different renders leaking into...
Read more >Using Non-SSR Friendly Components with Next.js
1. Use next/dynamic imports ... Next.js claims to support ES2020 dynamic import() for JavaScript. It allows you to import JavaScript modules dynamically and...
Read more >Emotion 10: CSS-in-JS with Flexible Scoped and Global ...
A new Global component enables dynamic global styling. ... Class names containing Emotion styles from the className prop override css prop ...
Read more >reactjs - Nextjs - Dynamic Imports - CSS Modules cannot be ...
I've never seen a "~" in an import path before, might that be causing a problem? – Mark Williams · @MarkWilliams I dont...
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
cc @mnajdova in case you want to work on https://github.com/emotion-js/emotion/issues/2158#issuecomment-761696862
The workaround proposed by @zce seems to do it.
The only downside is one invalid HTML markup. It’s OK-ish for a temporary solution. The global style can be rendered before any other content of the body. The warning only happens once, not flooding / burying the other important potential errors too much. However, in the long term, we need to fix it.
@Andarist We will keep it in mind, thanks for taking the time to share pointers on how you envision the solution. Maybe we can come back to it once we release v5 stable.