Skip to content
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

Different outputs of nested media queries #781

Open
vanyauhalin opened this issue Jul 30, 2024 · 0 comments
Open

Different outputs of nested media queries #781

vanyauhalin opened this issue Jul 30, 2024 · 0 comments

Comments

@vanyauhalin
Copy link

Hi. I have encountered an issue while using nested media queries with pseudo-elements. Look.

Setup

$ cat package.json
{
  "type": "module",
  "scripts": {
    "build": "node main.js"
  },
  "devDependencies": {
    "browserslist": "^4.23.2",
    "lightningcss": "^1.25.1"
  }
}
$ cat main.js
import browserslist from "browserslist"
import {browserslistToTargets, bundle} from "lightningcss"

function main() {
  const l = browserslist("> 0.25%")
  const t = browserslistToTargets(l)
  const r = bundle({
    drafts: {customMedia: true},
    filename: "main.css",
    minify: false,
    targets: t,
  })
  console.log(r.code.toString())
}

main()
$ cat main.css
@custom-media --m (width >= 1px);

.a::before,
.a::after {
  display: block;
}

.a::before {
  @media (--m) {
    content: "";
  }
}

.a::after {
  @media (--m) {
    content: "";
  }
}

.b::before,
.b::after {
  display: block;
  @media (--m) {
    content: "";
  }
}

Current

$ pnpm build
.a:before, .a:after {
  display: block;
}

@media (min-width: 1px) {
  .a:before {
    content: "";
  }
}

@media (min-width: 1px) {
  .a:after {
    content: "";
  }
}

.b:before, .b:after {
  display: block;
}

@media (min-width: 1px) {
  :is(.b:before, .b:after) {
    content: "";
  }
}

Expected

$ pnpm build
.a:before, .a:after {
  display: block;
}

@media (min-width: 1px) {
  .a:before, .a:after {
    content: "";
  }
}

.b:before, .b:after {
  display: block;
}

@media (min-width: 1px) {
  .b:before, .b:after {
    content: "";
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant