-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Nested CSS parsing broken/bypassed when composing class from another css modules file #796
Comments
Hi @viveleroi This doesn't appear to be an issue with Can you file an issue on their repo? As a work around you can avoid |
You can also use @import url('../../forms.module.css');
.textarea {
composes: formfield;
} I've created a minimal reproduction that illustrates the fix : https://github.com/romainmenke/vite-css-modules--postcss--bug-1#readme Going to close this because it has been confirmed that the issue is coming from CSS Modules. The way they import/inline classes with |
Thanks for the effort and alternate solution. Can you recommend the best place for me to file this issue? Vite? |
I am not familiar with either Vite or CSS Modules :/ I think only the author of the PostCSS plugins related to CSS Modules can fix this. |
I've filed an issue for the postcss modules plugin vite uses. Looking into the import plugin, it looks like it will only work for composes because that will add the imported class to the element, hiding the fact that the class name hash is different than what is was in the original file. I don't think the import is at all aware of the css module system, so it's just causing new hashes to be made. I noticed this when trying to target an imported class. The class in my DOM was ._inputWithButton_11xe0_69 ._secondary_11xe0_82{
border-bottom-left-radius: 0;
border-top-left-radius: 0;
} I've tried various things to fix it, they just seem incompatible. |
Ah, yes, I indeed don't know anything about CSS Modules, so I am unable to verify if the output is valid. I was only able to determine that the plugins like Good to know that |
Bug description
I'm using this plugin with CSS Modules via Vite 4.0.4 (in a react project).
I'm trying to uses
composes
on a class in another modules file. That class has nested CSS. When I import that CSS using:composes: formfield from '../../forms.module.css';
All of the nested code gets printed to the DOM - it somehow was not parsed into output CSS.
If I import that css module directly in my TS:
import formStyles from '../../forms.module.css'
and applyformStyles.formfield
to my element'sclassName
, everything works as expected, which is why I'm filing the bug here.When I move the class to a global css file and use
composes: formfield from global;
, the nesting works as expected.Source CSS
in textarea.module.css:
in forms.module.css:
Expected CSS
Does it happen with
npx @csstools/csstools-cli <plugin-name> minimal-example.css
?None
Debug output
No response
Extra config
No response
What plugin are you experiencing this issue on?
PostCSS Nesting
Plugin version
10.2.0
What OS are you experiencing this on?
Windows
Node Version
18.9.1
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: