-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
fix: ensure non-matching elements are scoped for :not(...)
selector
#13999
Conversation
If the contents of a `:not` selector don't match, then it's actually a match for `:not` because it's inverted. Therefore, we need to scope such elements. Fixes #13974
🦋 Changeset detectedLatest commit: a1f3cbd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
This change will mark elements as scoped and add the <div class="a">aaa</div>
<div>bbb</div>
<style>
:not(.b) {
background-color: blue;
}
</style> |
You're right this is a limitation of this approach - either we say "this is rare enough so we don't care" or we gotta make this lazy (i.e. "store this stuff somewhere until it matches and then scope all the other elements") |
Are we prevented from making this more precise in the future because it would be a breaking change for people who were inadvertently using the more generous behavior? Or do we not want to worry about those kinds of breaking changes? |
I think we're ok with this - there's already imperfect scoping in other places (like when we can't properly statically analyze things, and with enough effort we could in the future). The question around this is more about "do we want to do the additional effort which is a bit cumbersome but ultimately not that high directly for this specific case, or do we live with this edge case?". |
Isn't that correct? Both divs are not |
Revisiting this - this is actually a very interesting case. What do we do, if a <foo class=x>foo</foo>
<bar class=x>bar</foo>
<style>
:not(.x) { color: red; } /* right now this never matches, but is kept as used */
:not(.y) { color: green; } /* right now this always matches, but is removed as unused */
</style> Both cases arguably don't make much sense since one never matches because the contents of the |
…ed, when it never matches by always matching, it's unused
preview: https://svelte-dev-git-preview-svelte-13999-svelte.vercel.app/ this is an automated message |
What if the class is wrapped in a condition? This code worked in
UPDATED: #14168 - looks like it's already been discussed here. |
If the contents of a
:not
selector don't match, then it's actually a match for:not
because it's inverted. Therefore, we need to scope such elements.Fixes #13974
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint