Css classes are not splitted to treat output CSS effectively
See original GitHub issueAfter reading documentation and googling I nowhere found, how to make Emotion effective and split produced css code.
Version of Emotion: I have this issue on latest v 10.
Repro steps: I have component like this:
import styled from '@emotion/styled'
const StyledInput = styled.input`
box-sizing: border-box;
border: slim;
border-color: red;
color: ${(props: any) => myfunction(props.color || 'black')};
width: 100%;
`
And I use it two times like this:
<StyledInput color="red" />
<StyledInput color="green" />
Current CSS output:
.class1 {
box-sizing: border-box;
border: slim;
border-color: red;
color: red;
width: 100%;
}
.class2 {
box-sizing: border-box;
border: slim;
border-color: green;
color: red;
width: 100%;
}
Expected CSS output:
.commonClass {
box-sizing: border-box;
border: slim;
border-color: red;
width: 100%;
}
.class1 {
color: red;
}
.class2 {
color: red;
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Is it a good practice to split CSS? [closed] - Stack Overflow
If you working for development, yes, you need to separate CSS files because you can modify code very easily. If you are on...
Read more >Methods to Organize CSS
Class names are descriptive property names, not describing the semantic nature of the element, which can sometimes complicate development.
Read more >How To Optimize CSS for Peak Site Performance - Kinsta
There is a better option: Split CSS into separate files with clear levels of responsibility and document accordingly. Removing unnecessary ...
Read more >Organizing your CSS - Learn web development | MDN
Consistency can be applied in all sorts of ways, such as using the same naming conventions for classes, choosing one method of describing...
Read more >TailwindCSS: Adds complexity, does nothing.
This is not a bad thing. I have written, and used utility classes a great deal myself, especially when I'm writing CSS without...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sub and SubInRed are treated as completely separate components - each has its own unique class name and thus they SubInRed won’t be targeted by Title’s styles.
Technically we maybe could change this behavior, but I’m not convinced that we should. You could raise a separate issue about this so we could discuss this - we are working on v11 so this potentially could make it into that release, although keep in mind that we probably won’t decide to support this.
@Andarist my expectation would be :
SubInRed
will inherit the class name fromSub
Title
will turn onSub
’s display attribute.Instead, I got:
SubInRed
will NOT inherit any class name fromSub
.Title
will not affectSubInRed
.Previously this will work with the library where I came from (
linaria
). But from reading your comment above in this issue, I think this was the expected behavior by design. <- I just want to confirm this with you.Thanks!