-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
postcss-custom-media: incorrect rendering with nested rules #1519
Comments
With latest PostCSS Preset Env you get: .some-class .nested {
flex-direction: column;
}
@media (min-width: 480px) {
.some-class .nested {
flex-direction: row;
}
} This seems correct. Can you provide a complete reproduction that shows that the issue is with |
thank you |
@massimo-cassandro What was the issue then? |
Hi I'm using webpack and postcss. |
So your original output was also correct and the I just want to know if there is a tool that is producing incorrect output. Because if there is, then I should fix that. I can only fix what I understand :) |
I understand what you mean and I really appreciate your help. I did some more tests, and now, after rebuilding my initial configuration (but with postcss-preset-env). and I can't get the result of your demo anymore. Surely, I'm using some wrong config. I'm using PostCSS with webpack, this is my configuration before adding
I don't use postcss-nesting. My autoprefixer reads its config from a Honestly, I think it's all getting a bit too clunky, and I'm thinking about using Sass for media queries. I'm not too keen on it, I'd like to use custom media, but I don't want to spend hours configuring postCSS plugins... Thanks again for your help |
Thank you for providing this extra info. I tried this config as best as possible. However I don't get any broken output. For this input: .some-class {
.nested {
flex-direction: column;
@media (--xxs-only) {
flex-direction: row;
}
}
} I get: :where(html) {}
.some-class {
.nested {
flex-direction: column;
@media (min-width: 0px) and (max-width: 239px) {
flex-direction: row;
}
@media (--xxs-only) {
flex-direction: row;
}
}
} Is it possible that PostCSS is working correctly but that Webpack (or part of your Webpack config) is causing issues? I don't ever use Webpack to process CSS because Webpack is JavaScript bundler and not a CSS bundler. |
I use webpack because I need to process both js and css. I recently switched from rollup to webpack and found that it is the most convenient solution for my work. Thank You |
Sure! We have a recipe that is fairly similar to your config. The config is here: https://github.com/csstools/postcss-plugins/blob/repro-1519--ambitious-woodpecker-c6f183a4ef/postcss-recipes/open-props/postcss.config.js You can run that yourself by:
|
Tried cloning the repo: all works as expected |
One thing you could try is to use a dedicated CSS bundler like:
Then Webpack won't be tasked with processing multiple files, only your entrypoint. Might be worth it to create a minimal repro in a GitHub project. |
Thanks. As soon as I can, I'll try it and let you know |
found the problem. I honestly didn't imagine it could create such a conflict. I have other projects where I use sass with webpack and postcss (without postcss-custom-media), and I never had any problems. Thanks again for your help |
That is indeed surprising. Thank you for investigating further 🙇 |
Bug description
In custom media queries inside nested rules, the parent selectors are ignored
Source CSS
Expected CSS
Actual CSS
Playgound example
No response
Does it happen with
npx @csstools/csstools-cli <plugin-name> minimal-example.css
?N/A
Debug output
No response
Extra config
No response
What plugin are you experiencing this issue on?
PostCSS Custom Media Queries
Plugin version
11.0.5
What OS are you experiencing this on?
macOS
Node Version
22.3.0
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: