Skip to content

CSS pseudo selector with nested media query produces wrong styles in production mode #20006

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

Open
7 tasks done
7nik opened this issue May 7, 2025 · 1 comment
Open
7 tasks done
Labels
bug: upstream Bug in a dependency of Vite feat: css has workaround p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@7nik
Copy link

7nik commented May 7, 2025

Describe the bug

The following styles

div#app::after {
  content: "after";
  @media screen {
    background: red;
  }
}

in production mode gets compiled into

div#app:after{content:"after"}@media screen{{background:red}}

where the media query block loses the selector.

In dev mode the styles output is correct.

Reproduction

https://github.com/7nik/vite-css-media-nested-in-pseudoelem

Steps to reproduce

npm install
npm run dev — open http://localhost:5173/, the text background should be red
npm run build & npm run preview — open http://localhost:4173/, the text background should be red, but isn't

System Info

System:
    OS: Linux 6.6 Manjaro Linux
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700K
    Memory: 22.04 GB / 31.09 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 23.9.0 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 11.3.0 - /usr/bin/npm
    pnpm: 10.9.0 - /usr/bin/pnpm
  Browsers:
    Brave Browser: 134.1.76.81
    Chromium: 136.0.7103.59
  npmPackages:
    vite: ^6.3.1 => 6.3.5

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

This seems to be a bug in esbuild (esbuild try, evanw/esbuild#4164).

It seems css.transformer: 'lightningcss' works as a workaround.

@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite feat: css has workaround p2-edge-case Bug, but has workaround or limited in scope (priority) labels May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: upstream Bug in a dependency of Vite feat: css has workaround p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

No branches or pull requests

2 participants