Have you read the Contributing Guidelines on issues?
Prerequisites
Description
I’m using cascade layers, which are enabled by default in v3.9.2 (future: { v4: true } in the config).
I noticed that in the production build, CSS media queries are extracted out of their cascade layers.
In dev mode, the styles look like this:
@layer docusaurus.theme-classic {
/* some styles here */
@media (min-width: 997px) {
/* media query styles here */
}
}
But in the built CSS bundle they become:
@layer docusaurus.theme-classic {
/* some styles here */
}
@media (min-width: 997px) {
/* media query styles here */
}
The media queries are no longer nested inside the cascade layer.
This also happens to imported third-party stylesheets, which breaks the intended cascade order.
Reproducible demo
No response
Steps to reproduce
- Create a new Docusaurus project:
npx create-docusaurus@latest my-website classic
- Navigate into the project directory:
cd my-website
- Start the development server:
npm start
- Open the site in a browser and inspect the applied CSS in DevTools (Sources panel).
Observe: media queries are correctly nested inside their corresponding cascade layers.
- Build the production bundle:
npm run build
- Serve the built site:
npm run serve
- Open the site again in a browser and inspect the built CSS in DevTools (Sources panel).
Observe: all media queries have been extracted out of the cascade layers and appear at the root level of the stylesheet.
Expected behavior
Media queries should remain nested inside their respective cascade layers in the production CSS bundle, exactly as they appear during development. The cascade layer structure should be preserved for both local and third-party stylesheets.
Actual behavior
During the production build, all media queries are extracted out of their cascade layers and moved to the root level of the compiled CSS. As a result, the cascade layer ordering is broken, affecting both project styles and imported third-party stylesheets.
Your environment
- Public source code: N/A (bug reproducible in a fresh project)
- Public site URL: N/A
- Docusaurus version used: 3.9.2 (with
future: { v4: true } enabled by default)
- Environment name and version (e.g. Chrome 89, Node.js 16.4): all browsers, Node.js 22.14.0
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 11, macOS 26.2
Self-service
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clearoryarn clearcommand.rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages.Description
I’m using cascade layers, which are enabled by default in v3.9.2 (
future: { v4: true }in the config).I noticed that in the production build, CSS media queries are extracted out of their cascade layers.
In dev mode, the styles look like this:
But in the built CSS bundle they become:
The media queries are no longer nested inside the cascade layer.
This also happens to imported third-party stylesheets, which breaks the intended cascade order.
Reproducible demo
No response
Steps to reproduce
npx create-docusaurus@latest my-website classiccd my-websitenpm startObserve: media queries are correctly nested inside their corresponding cascade layers.
npm run buildnpm run serveObserve: all media queries have been extracted out of the cascade layers and appear at the root level of the stylesheet.
Expected behavior
Media queries should remain nested inside their respective cascade layers in the production CSS bundle, exactly as they appear during development. The cascade layer structure should be preserved for both local and third-party stylesheets.
Actual behavior
During the production build, all media queries are extracted out of their cascade layers and moved to the root level of the compiled CSS. As a result, the cascade layer ordering is broken, affecting both project styles and imported third-party stylesheets.
Your environment
future: { v4: true }enabled by default)Self-service