linaria icon indicating copy to clipboard operation
linaria copied to clipboard

The same CSS styles are applied multiple times to an element on the build mode

Open dmitry-pokhmelnov opened this issue 4 years ago • 3 comments

Environment

  • Linaria version: 1.3.3

Description

I have some components loaded dynamically by using dynamic import() and React. lazy. Dynamic loading produces a CSS chunk for each component in the production build mode If I have a test component as a part of other components that loads dynamically, I get CSS chunks for each dynamically loaded component with exactly the same className for my test component

Issues

The same CSS selectors are in different CSS chunks; The same CSS styles are applied at least 2 or more times; It makes impossible to override CSS styles with styled(SomeComponent) because duplicated styles override each other and sometimes have a higher priority.

image

Styled-components don't have this issue because they generate a unique classNames

Question

Based on my current understanding, this issue might be resolved if we apply chunk name to class name produced by linaria. It will result in generating a unique class name selector for each CSS chunk. Do you think it's possible to apply a chunk name for each CSS selector produced by linaria?

Reproducible Demo

https://github.com/dmitry-pokhmelnov/bug-repro-linaria

dmitry-pokhmelnov avatar Oct 05 '20 11:10 dmitry-pokhmelnov

just FYI. I tried the demo with linaria 2.0.0-rc.3 and the behaviour is still there image

jevangelista-quizlet avatar Oct 15 '20 20:10 jevangelista-quizlet

The reason for this problem is that webpack generates a css file for every chunk loaded with lazy-load. But after switching between pages, react does not remove already included css files. This issue is very similar to this one https://stackoverflow.com/questions/66531412/dynamically-load-and-unload-content-of-css-file-in-javascript-react

DiFuks avatar Jun 23 '22 10:06 DiFuks

Any update on this ? This is happening to me while I am using *.module.scss

gajraj-gan avatar Aug 24 '23 11:08 gajraj-gan