Issue when using CacheProvider in Gatsby (SSR)
See original GitHub issueCurrent behavior:
I’m building a gatsby website with emotion. I have a custom ui library with a wrapper that looks something like this:
const MyWrapper = ({ children, key = "stl" }) => {
const myCache = createCache({ key })
// I also have a custom container setup and some global styles but this is enough to reproduce the issue
return <CacheProvider value={myCache}>{children}</CacheProvider>
}
With the follow landing page on my gatsby application:
<MyWrapper>
<div
css={css`
color: green;
`}
>
Hello world!
</div>
</MyWrapper>
I get the following error when I use the built version of the application:
If you disable javascript, the page loads and looks fine so I’m guessing something is going wrong when rehydrating. It looks like it’s happening in react-dom so I don’t think it’s related to gatsby. Feel free to close the issue if you think otherwise.
Maybe related: https://github.com/emotion-js/emotion/pull/1396
Thank you for your help 🙏
To reproduce:
git clone https://github.com/kombucha/gatsby-emotion-bug.git
yarn
yarn serve
(this will build and serve the gatsby website, ie not development mode)- Go to http://localhost:9000/. You should see an error.
Expected behavior:
It should rehydrate the application without error.
Environment information:
react
version: 16.9emotion
version: 10.0.15gatsby-plugin-emotion
version: 4.1.2
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Debugging Cache Issues - Gatsby
Debugging Cache Issues. There can be certain scenarios in which the Gatsby caching mechanism appears to fail, which can lead to issues like:...
Read more >Gatsby JS — How to solve FOUC when using tss-react and ...
This post is about how I solved the FOUC-problem in my Gatsby JS website after migrating to Material UI v5 with tss-react ....
Read more >Server Side Rendering - Emotion
If using a custom cache, ensure you are creating a new cache per server render within gatsby-ssr.js . This will differ from the...
Read more >Emotion + Gatsby Serve: theme does not load except after ...
To me, it seems that you need to add some SSR (Server-Side Rendering) to @emotion . Have you tried something like:
Read more >Going to Production - Next.js
Before taking your Next.js application to production, here are some recommendations to ensure the best user experience. ... ssr-caching.
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
Closing because the fix for it has been merged, we hope to release v11 soon-ish.
@zslabs you have such style generated:
and it’s applied to at least one of the
<style>
elements before we have a chance to move them out of the way (when JS loads and executes). I would recommend writing more specific css for this one or you could try to setstyle { display: none !important; }
globally.