-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
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:
emotion/packages/cache/src/index.js
Lines 55 to 60 in 1e10d8c
const ssrStyles = document.querySelectorAll(`style[data-emotion]`) | |
// get SSRed styles out of the way of React's hydration | |
// document.head is a safe place to move them to | |
Array.prototype.forEach.call(ssrStyles, (node: HTMLStyleElement) => { | |
;((document.head: any): HTMLHeadElement).appendChild(node) | |
}) |
To reproduce:
- 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).
- Visit a page that uses emotion 11 in production mode (I've made a test app here: https://github.com/craigsketchley/emotion-11-app).
- 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