Why does emotion have to repeat all css properties for every little change? #2746
Replies: 2 comments
-
I found that this is called static extraction? I understand that automatically extract properties might be difficult, but what i ask is just let me control generated classnames manually and not in runtime. Kinda make css property work similarly with className + cx. |
Beta Was this translation helpful? Give feedback.
-
Hey @faradaytrs, I have an open PR about adding a "Best Practices" page to the docs. This section about dynamic styles may be of interest to you. As you said, you can use Currently, Emotion does not do static extraction, unless you count some of the CSS prop optimizations done by |
Beta Was this translation helpful? Give feedback.
-
For example, we have two blocks:
This will result in two divs having the same classname, which is expected.
But if we add one dynamic variable:
It will result in them having completely different classnames, and although most of css properties they use are the same and obviously static, it will copy paste them many times under different classname.
If we have many versions of the same element on the page with a lot of static css and just one line difference it will result in large build size.
Why can't emotion detect static part of the css and detect separate classname for static and dynamic styles?
It would be awesome if it generates:
I can kinda manually achieve such result by using className property in combination with cx. But it will generate styles in runtime instead. Only css property is handled by compiler.
Beta Was this translation helpful? Give feedback.
All reactions