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.

Loading a second emotion bundle shouldn't break the first

See original GitHub issue

Current behavior:

I’m trying to run emotion 11 in a browser extension content script. The trouble is if that content script then runs in a page that is already running an emotion 11 app, then the app styles break. After a chat with @Andarist on the emotion-slack, he suggested I open an issue here and that this is probably the culprit: https://github.com/emotion-js/emotion/blob/1e10d8c9aa91ce443d29661a7f830190d42aae92/packages/cache/src/index.js#L55-L60

To reproduce:

  1. Build and install a browser extension that uses emotion 11 in a content script (I’ve made a test extension here: https://github.com/craigsketchley/emotion-11-extension).
  2. Visit a page that uses emotion 11 in production mode (I’ve made a test app here: https://github.com/craigsketchley/emotion-11-app).
  3. Watch styles break as soon as the content script loads.

Expected behavior:

Loading a second bundle which includes emotion 11 shouldn’t break the styles of the existing emotion 11 app already running in the page.

Environment information:

In the app and extension:

  • react version: 16.13.1
  • @emotion/cache version: 11.0.0-next.13
  • @emotion/react version: 11.0.0-next.13
  • @emotion/styled version: 11.0.0-next.13

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
Andaristcommented, Oct 1, 2020

I finally got to it and prepared a PR for this, you can track it here: https://github.com/emotion-js/emotion/pull/2028

0reactions
arturbiencommented, Oct 27, 2021

@Andarist sorry for the false alarm. I have a project inside a monorepo with multiple yarn workspaces and packages, and somehow the webpack bundled older version of /styled and /react package from the root folder causing the issue. Running “yarn upgrade” in the root of the repo and then in the extension workspace solved the problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Emotion 11
Emotion 11 is a slight evolution over the Emotion 10. It focuses mainly on the developer experience, TS types improvements, switches internals to...
Read more >
External component libraries using emotion not rendering ...
When the page first loads my components, none of the emotion injected styles are active on the components, and then after a second...
Read more >
Why We're Breaking Up with CSS-in-JS - DEV Community ‍ ‍
I'm using Emotion with server-side rendering and MUI/Mantine/(another Emotion-powered component library) and it's not working because... While ...
Read more >
Rising Strong by Brené Brown - Book Summary - MeaningfulHQ
Brown tells us that our bodies respond to EMOTION FIRST, and they often direct us ... We can't pack down hurt, nor can...
Read more >
FAQs - styled-components
If you are a library author, we recommend that you should not bundle and ship styled-components module with your library. There are two...
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