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

CSS Nesting: multiple children #3096

Closed
joelmoss opened this issue May 1, 2023 · 3 comments
Closed

CSS Nesting: multiple children #3096

joelmoss opened this issue May 1, 2023 · 3 comments

Comments

@joelmoss
Copy link

joelmoss commented May 1, 2023

Think this is a bug in esbuild when transforming down CSS nesting...

This input needs no transforming, and all works. It will style span and label siblings of input:

input + span,
input + label {
  color: red;
}

But introducing nesting:

input {
  + span,
  + label {
    color: red;
  }
}

Results in this output:

input :is(+ span, + label) {
  color: red;
}

Which is invalid and incorrect, and will not style the siblings span and label of input.

@evanw evanw closed this as completed in a3fcf70 May 12, 2023
@joelmoss
Copy link
Author

thanks for the fix, but the issue still persists with pseudo-elements...

a {
  &::before,
  &::after {
    content: "???";
  }
}

which will result in...

a:is(::before, ::after) {
  content: "???";
}

Which again, will not work.

@evanw
Copy link
Owner

evanw commented May 15, 2023

As far as I can tell, pseudo-elements deliberately don't work with CSS nesting according to the CSS nesting specification (https://www.w3.org/TR/css-nesting-1/#ref-for-matches-pseudo%E2%91%A0):

The nesting selector cannot represent pseudo-elements (identical to the behavior of the :is() pseudo-class).

So I believe esbuild is working correctly here. Both a { &::before {} } and a:is(::before) {} are equivalent according to the specification, and are equally invalid. Transforming a { &::before {} } into a::before {} would be incorrect because it's not equivalent.

@joelmoss
Copy link
Author

Well that's interesting, as this works in Chrome 113

a {
  &::before,
  &::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

2 participants