emotion-js / emotion

👩‍🎤 CSS-in-JS library designed for high performance style composition
https://emotion.sh/
MIT License
17.5k stars 1.11k forks source link

Custom CacheProvider not consistently being applied to imported component libraries using emotion. #3169

Open jmdarling opened 7 months ago

jmdarling commented 7 months ago

Current behavior:

My custom CacheProvider is not consistently "grabbing" styles imported from a library, resulting in injected <style> tags not having the expected data-emotion attribute and nonce attribute.

Screenshot 2024-03-27 at 8 16 39 PM

To reproduce:

Reproduction repository: https://github.com/jmdarling/emotion-library-caching-issue

  1. Clone the repository: git clone https://github.com/jmdarling/emotion-library-caching-issue
  2. Install dependencies: npm install
  3. Build the library: npm run build
  4. Start the development server: npm run dev
  5. Open your browser and navigate to http://localhost:5173

Expected behavior:

My custom CacheProvider will properly "grab" styles imported from a library and I will see the correct data-emotion attribute and nonce attribute on injected <style> tags.

Environment information:

sshishov commented 5 months ago

We have the same issue, but instead of CacheProvider we are using:

createEmotion({key: 'default', nonce: 'nonce'}).css(styleObj);

Somehow we are getting some elements with key='css' and without nonce

Andarist commented 5 months ago

@jmdarling most likely you end up with multiple copies of @emotion/react used in your app

@sshishov you'd have to create a repro for the problem and the separate issue for it to get further help on this one

jmdarling commented 4 months ago

@Andarist - I validated in my reproduction shared in this ticket that there is only a single copy of @emotion/react. That was the first thing I thought too, but no dice.

uladzimirdev commented 3 months ago

@Andarist happens to us with Mantine v6, I double checked and the only version of @emotion/react is used. At the same time mantine/styles reexports createEmotionCache

uladzimirdev commented 3 months ago

@jmdarling did you find any workaround?