-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
:has(...)
contents are not scoped
#13395
Milestone
Comments
I'd expect it to follow a very simple rule: if the selector is not inside |
dummdidumm
added a commit
that referenced
this issue
Oct 11, 2024
The main part of #13395 This implements scoping for selectors inside `:has(...)`. The approach is to first descend into the contents of a `:has(...)` selector, then in case of a match, try to match the rest of the selector ignoring the `:has(...)` part. In other words, `.x:has(y)` is essentially treated as `x y` with `y` being matched first, then walking up the selector chain taking into account combinators. This is a breaking change because people could've used `:has(.unknown)` with `.unknown` not appearing in the HTML, and so they need to do `:has(:global(.unknown))` instead
5 tasks
dummdidumm
added a commit
that referenced
this issue
Oct 11, 2024
The other part of #13395 This implements scoping for selectors inside `:not(...)`. The approach is almot the same as for `:is/where(...)`. This is a breaking change because people could've used `:not(.unknown)` with `.unknown` not appearing in the HTML, and so they need to do `:not(:global(.unknown))` instead. While implementing it I also discovered a few bugs, which are fixed in this PR: - `foo :is(bar baz)` wasn't properly handled. This selector can mean `foo bar baz` but it can also mean `bar foo baz` (super weird, but it is what it is). Since our current algorithm isn't suited for handling this, we just assume it matches and scope it. Worst case is we missed a prune - `bar` in `:global(foo):is(bar)` was always marked as unused, even if it matched
5 tasks
dummdidumm
added a commit
that referenced
this issue
Oct 14, 2024
The main part of #13395 This implements scoping for selectors inside `:has(...)`. The approach is to first descend into the contents of a `:has(...)` selector, then in case of a match, try to match the rest of the selector ignoring the `:has(...)` part. In other words, `.x:has(y)` is essentially treated as `x y` with `y` being matched first, then walking up the selector chain taking into account combinators. This is a breaking change because people could've used `:has(.unknown)` with `.unknown` not appearing in the HTML, and so they need to do `:has(:global(.unknown))` instead
dummdidumm
added a commit
that referenced
this issue
Oct 15, 2024
The other part of #13395 This implements scoping for selectors inside `:not(...)`. The approach is almot the same as for `:is/where(...)`. This is a breaking change because people could've used `:not(.unknown)` with `.unknown` not appearing in the HTML, and so they need to do `:not(:global(.unknown))` instead. While implementing it I also discovered a few bugs, which are fixed in this PR: - `foo :is(bar baz)` wasn't properly handled. This selector can mean `foo bar baz` but it can also mean `bar foo baz` (super weird, but it is what it is). Since our current algorithm isn't suited for handling this, we just assume it matches and scope it. Worst case is we missed a prune - `bar` in `:global(foo):is(bar)` was always marked as unused, even if it matched
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
This...
...becomes this:
That's consistent with Svelte 4, but it's not consistent with how Svelte 5 handles
:is(...)
and:where(...)
. If we scoped the selector list, then either those styles would be removed as unused, or transformed into this:The fourth functional pseudo-class is
:not(...)
.Options:
:global(x).has(y)
would not scopey
):has
but not:not
or vice versaI don't know off the top of my head what the right answer is, but it would be good to have consistency.
Reproduction
link
The text was updated successfully, but these errors were encountered: