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.

importing the CSS helper from @emotion/css instead of @emotion/react seems to not work

See original GitHub issue

Current behavior:

If I have @emotion/css as a dependency (which I do because I need to disable speedy for puppeteer/prerender.io runs) then whenever I try to use the css prop with the css helper, TypeScript suggests to import the css helper from @emotion/css instead of @emotion/react. but if I actually use that, it has no effect on the actual page.

I’m using the emotion babel plugin, in a CRA app that uses craco to edit the babel config.

I work around this by adding a restricted import ESLint rule to yell at any and all who try to use the css helper from a @emotion/css import.

To reproduce:

https://www.github.com/osdiab/emotion-css-prop-repro

Expected behavior:

It works to avoid confusing my teammates

Environment information:

  "dependencies": {
    "@craco/craco": "^6.1.2",
    "@emotion/core": "^11.0.0",
    "@emotion/css": "^11.1.3",
    "@emotion/react": "^11.4.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
  },

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
chunlawcommented, Sep 28, 2021

@Andarist just doing what the docs told me to! https://emotion.sh/docs/ssr#puppeteer I’ll try doing that instead, but not exactly sure how to use CacheProvider.

Hope below code fragment help you or anyone

import { CacheProvider } from "@emotion/react";
import createCache from "@emotion/cache";

// if you are using mui v5
import { ThemeProvider } from '@mui/material/styles';

const emotionCache = createCache({
  key: "emotion-cache-no-speedy",
  speedy: false,
});

const theme = createTheme();

const App = () => {
  return (
    <ThemeProvider theme={theme}>
      <CacheProvider value={emotionCache}>
        <div>Your app here</div>
      </CacheProvider>
    </ThemeProvider>
  )
}
0reactions
dylanmatecommented, Sep 20, 2022

@Andarist just doing what the docs told me to! https://emotion.sh/docs/ssr#puppeteer I’ll try doing that instead, but not exactly sure how to use CacheProvider.

Hope below code fragment help you or anyone

import { CacheProvider } from "@emotion/react";
import createCache from "@emotion/cache";

// if you are using mui v5
import { ThemeProvider } from '@mui/material/styles';

const emotionCache = createCache({
  key: "emotion-cache-no-speedy",
  speedy: false,
});

const theme = createTheme();

const App = () => {
  return (
    <ThemeProvider theme={theme}>
      <CacheProvider value={emotionCache}>
        <div>Your app here</div>
      </CacheProvider>
    </ThemeProvider>
  )
}

@Andarist - can you add this (or a link to it) to the SSR documentation? The puppeteer solution in the doco did not work for me but this did.

Sorry OP for hijacking your ticket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The css Prop - Emotion
The primary way to style elements with emotion is the css prop. It provides a concise and flexible API to style your components....
Read more >
react-emotion's CSS not present in DOM - Stack Overflow
It's currently a problem with Chrome. Emotion uses some kind of Chrome magic, so it doesn't need to render it's CSS to the...
Read more >
Style library interoperability - Material UI - MUI
Plain CSS; Global CSS; Styled Components; CSS Modules; Emotion ... import * as React from 'react'; import Slider from '@mui/material/Slider'; import '.
Read more >
FAQs - styled-components
At this time we do not recommend using @import within cGS due to some issues ... In general, always use the css helper...
Read more >
Use CSS or SCSS instead of Emotion? - Get Help
Then, instead of import CSS files directly (we don't allow CSS files ... This may not seem important, but when you work with...
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