Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS Modules duplicates composes dependencies onto page, re-declaring classes #15683

Open
7 tasks done
privatenumber opened this issue Jan 22, 2024 · 2 comments · May be fixed by #16018
Open
7 tasks done

CSS Modules duplicates composes dependencies onto page, re-declaring classes #15683

privatenumber opened this issue Jan 22, 2024 · 2 comments · May be fixed by #16018

Comments

@privatenumber
Copy link
Sponsor Contributor

privatenumber commented Jan 22, 2024

Describe the bug

I'm facing a problem with the composes feature in CSS Modules using LightningCSS. It seems to duplicate the base class it's composing, causing a re-declaration. Consequently, this re-declaration overwrites styles from components loaded earlier that also composes the same base class, dominating in specificity and altering their intended look.

Disabling LightningCSS resolves the issue, but there are other problems with PostCSS (e.g., #10079).

Reproduction

https://stackblitz.com/edit/vitejs-vite-vf7fy6?file=vite.config.js

Steps to reproduce

Just load the StackBlitz.

For context, I'm encountering this problem in a Vue.js app. But the reproduction minimizes it down to just JS + CSS Modules.

System Info

N/A

Used Package Manager

npm

Logs

No response

Validations

Tasks

No tasks being tracked yet.
Copy link

stackblitz bot commented Jan 22, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@privatenumber privatenumber changed the title LightningCSS duplicates CSS Modules LightningCSS duplicates CSS Modules composes Jan 22, 2024
@privatenumber
Copy link
Sponsor Contributor Author

I actually managed to reproduce this with PostCSS too: https://stackblitz.com/edit/vitejs-vite-vhmmza?file=comp-a%2Findex.js

In both cases, it seems like anything CSSModules imports is handled outside of Vite and so shared dependencies are duplicated, creating unpredictable behavior based on what gets loaded on the page first.

@privatenumber privatenumber changed the title LightningCSS duplicates CSS Modules composes CSS Modules duplicates composes dependencies onto page, re-declaring classes Jan 23, 2024
@privatenumber privatenumber linked a pull request Feb 23, 2024 that will close this issue
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant