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.

createPortal and emotion in a gatsby site is not working

See original GitHub issue

I am opening this issue as a duplicated one I’ve just posted in gatsby, since I don’t know where it belongs

I think it is a gatsby issue, but I’m opening this one just to be sure

Here https://github.com/gatsbyjs/gatsby/issues/27352 I am using createPortal as seen here

And when embedded in gatsby, it works in gatsby development but not in gatsby build

This happens with and without the @emotion plugins

  "plugins": ["emotion", "@babel/plugin-proposal-class-properties"]

So I’m not sure who is responsible, whether gatsby or emotion 😅

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Oct 14, 2020

Oh, I’ve focused on the iframe and not on the main page itself 🤦 The fix is simple - just add a custom key option when creating that custom cache. We’ve already added an error about this in the upcoming Emotion 11: https://github.com/emotion-js/emotion/blob/ff4ee9d1623c2ad15a6ce9fa7a81ee8809683dad/packages/cache/src/index.js#L48-L53

This happens because the development workflow doesn’t use SSR and at the time of cache creation there are no style elements on the page, however when you are using SSR there are already style elements there and because the same default cache key has been used for both the builtin and custom caches they fought over those elements and the second cache created (the custom one) moved those style elements into the iframe and thus removing them from the main page and leaving it unstyled.

0reactions
1-800-jonocommented, Nov 16, 2022

How to add a custom key option?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to render a React component styled with Emotion in an ...
Components are styled using Emotion and the demo site is built with Gatsby. For preview purposes, I'd like to render components in an...
Read more >
gatsby-plugin-portal
If you want to use React Portals in your gatsby site, this is a simple way to add the required div element to...
Read more >
How to render a React component styled with Emotion in an ...
Coding example for the question How to render a React component styled with Emotion in an iframe in Gatsby site?-Reactjs.
Read more >
Accessible modals in Gatsby using portals - Level Up Coding
Adding a modal (dialog) to your website or app is a common scenario. ... could cause issues with positioning (z-index, overflow: hidden).
Read more >
gatsby-theme-newrelic - npm
This theme contains contains common configuration and shared components used across New Relic Gatsby sites. It is primarily used on the ...
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