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.

Production build returns multiple styles

See original GitHub issue

Current behavior:

I use Emotion with “@emotion/babel-preset-css-prop”. In production environment Emotion creates multiple style tags. This is desired for the dev environment, but not for production.

To reproduce:

  1. For testing purposes I have created a simple React component.
class Welcome extends React.Component {
  render() {
    return (
      <div css={{ backgroundColor: 'red' }}>
        <div css={{ color: 'yellow'}}>Yellow div</div>
    );
  }
}
  1. In the .babelrc within the production env, I have added within the presets at the first place the @emotion/babel-preset-css-prop.
"production": {
  "presets": [
    ["@emotion/babel-preset-css-prop"],
    [
      "@babel/preset-env",
      {
        "useBuiltIns": false,
        "targets": {
          "browsers": ["last 2 versions"]
        },
        "debug": false
      }
    ],
    ["@babel/preset-typescript"],
    "@babel/preset-react"
  ],
  "plugins": [ .... ]
  1. I get one global stylesheet file, but each css styling gets rendered in a new style tag within the html head. This is on purpose for the dev build, but not for production mode.

Given the component above my head looks as following:

<style data-emotion="css-global"></style>
<style data-emotion-css="f5yfbg">.css-f5yfbg{background-color:red;}</style>
<style data-emotion-css="fsfbn2">.css-fsfbn2{color:yellow;}</style>

I read all issues regarding to Emotion, but I couldn’t find something similiar.

Expected behavior:

Emotion should render one single stylesheet file.

Environment information:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
IRediTOTOcommented, Sep 28, 2020

I really want create a seperate css file, don’t like css in html. 😦 it can make site slow down (1% i think XD)…

0reactions
SimonKlausLudwigcommented, Sep 20, 2020

@baldurh baldurh How did you get it working ? Could you append a codesnippe or point me to the right direction ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React: Production build looks different from development build
I have a React/Django app that's behaving differently when built for production that it does when run on the development ...
Read more >
Angular workspace configuration
Angular CLI comes with two build configurations: production and development . ... See more in the Styles and scripts configuration section.
Read more >
Organizing your CSS - Learn web development | MDN
Break large stylesheets into multiple smaller ones ... In cases where you have very different styles for distinct parts of the site, you...
Read more >
Strict Mode - React
Strict mode checks are run in development mode only; they do not impact the production build. You can enable strict mode for any...
Read more >
E CSS in JS | Client-Side Web Development
But almost all of them will either generate an inline style to inject into an element, or will produce their own injected stylesheet...
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