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 issue when attribute selectors are used with @emotion/styled approach

See original GitHub issue

Current behavior:

Attribute selector doesn’t work in production build when the styled approach is used. Currently, it can be solved by using css`` approach instead.

To reproduce:

  1. Create an empty react CRA project
  2. Use the following styled component styles:
const ComponentStyled = styled.div`
  &[data-placement*='top'] .nested-element-selector {
    <any rules here>
  }
`;

Expected behavior:

CSS styles should be applied for production build, but it is working only in dev.

Environment information:

  • react version: 17.0.1
  • @emotion/react version: 11.1.4
  • @emotion/styled version: 11.0.0
  • @emotion/css version: 11.1.3

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
william57mcommented, Dec 17, 2021

Any news on that? Seems like selector are still not usable in production.

1reaction
Andaristcommented, Mar 11, 2021

@avmalyutin thank you for the repro case - it was really helpful and I’ve prepared a fix for this issue based on it: https://github.com/emotion-js/emotion/pull/2283

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styled-components vs. Emotion for handling CSS
Explore the benefits, drawbacks, and differences between two CSS-in-JS libraries: styled-components and Emotion-JS.
Read more >
How To Use Emotion for Styling in React | DigitalOcean
Learn how to style components in React using the emotion CSS-in-JS library.
Read more >
Attribute selectors - CSS: Cascading Style Sheets | MDN
It is often used for language subcode matches. [attr^=value]. Represents elements with an attribute name of attr whose value is prefixed ( ...
Read more >
The css Prop - Emotion
Babel Preset. This method will not work with Create React App or other projects that do not allow custom Babel configurations. Use the...
Read more >
Quick Introduction to Styling React Components with Emotion
In React, we can use inline styling using the style property that is available for all components. There are drawbacks to this approach...
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