It appears the media query is ignored when determining how to optimize the CSS. CSS nesting is a new feature, but nesting @ rules is part of the spec (MDN). It looks like nextjs uses postcss-nested, which I suspect is where the root issue is, but that package looks to be unmaintained, not updated in over a year, in favor of postcss-nesting, which is intended to implement the draft spec.
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/css-module-compilation-mashing-ghp469
To Reproduce
Current vs. Expected behavior
The background color of the centered div is expected to be red at all screen widths, but isn't.
Provide environment information
Which area(s) are affected? (Select all that apply)
Webpack
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
A CSS module defined as
gets compiled to a single rule
It appears the media query is ignored when determining how to optimize the CSS. CSS nesting is a new feature, but nesting @ rules is part of the spec (MDN). It looks like nextjs uses
postcss-nested
, which I suspect is where the root issue is, but that package looks to be unmaintained, not updated in over a year, in favor ofpostcss-nesting
, which is intended to implement the draft spec.Workarounds
Reorder css nesting
Reordering the nesting as
appears to compile correctly
Add
postcss-nesting
pluginAdding
"plugins": ["postcss-nesting"]
topostcss.config.js
causes the css to be compiled correctly.