question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue when using CacheProvider in Gatsby (SSR)

See original GitHub issue

Current 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: Screenshot 2019-08-11 at 13 38 33

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:

  1. git clone https://github.com/kombucha/gatsby-emotion-bug.git
  2. yarn
  3. yarn serve (this will build and serve the gatsby website, ie not development mode)
  4. Go to http://localhost:9000/. You should see an error.

Expected behavior:

It should rehydrate the application without error.

Environment information:

  • react version: 16.9
  • emotion version: 10.0.15
  • gatsby-plugin-emotion version: 4.1.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Andaristcommented, Apr 18, 2020

Closing because the fix for it has been merged, we hope to release v11 soon-ish.

2reactions
Andaristcommented, Jan 9, 2020

@zslabs you have such style generated:

.ck-1iz4joc > * > * {
    display: inline-block;
    transition: transform 0.25s cubic-bezier(0.175,0.885,0.320,1.275);
    transform-origin: center center;
    backface-visibility: hidden;
}

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 set style { display: none !important; } globally.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found