-
Notifications
You must be signed in to change notification settings - Fork 718
[selectors] Should :not(foo) match the host of the shadow tree? #10179
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
Comments
An author reason for not matching the host with Say I want to style :not(.foo) img { ... } If I would instead have to write: :host :not(.foo) img { ... } or add some other selector outside |
Yeah that's a really good point. |
I think it’s important to preserve the expectation that The |
Well, * wouldn't match the host. |
Consider Logically it can be a bit strange if I think the possibilities are:
|
I think there might be a third option which even though it's a bit weird would be an improvement on (1) if we go that route, which is conditioning matching it on the selector having a :host selector in some way (which was my read of the spec). Depending on how we define that, it could make |
This has some pitfalls, though: The mere presence of :host would influence the rest of the selector. We probably don't want this situation:
Not to mention the forward-compat issues we had with nesting, where people were worried about what would happen if something unknown to the browser (from a future spec) was nest-containing. You have a similar problem here with “host-containing”. TBH I'm not too worried about performance here; it's just one more element to match in a potentially very long chain, and if you want to optimize that out by checking for |
Not necessarily, right? The |
So if I understand correctly, your proposal would be that a selector needs to fall into one of these cases:
Then, for simple selectors:
For selector lists: same as I'm less sure about compound and complex selectors:
|
Whoops, sorry for missing this! For the general behavior, @lilles got it exactly right - the point of featurless-ness is to make it so that authors don't have to think about the host elements most of the time and will still get the likely intended behavior, so (In other words, Lea's request that For the more complex cases, I hadn't actually thought thru those cases when writing up the feature, but I think @Loirooriol's breakdown works well. For the more complex :not() cases, I think we might want to add the following:
This would make both of the complex :not() cases "not allowed to match the host". |
The CSS Working Group just discussed
The full IRC log of that discussion<RRSAgent> I have made the request to generate https://www.w3.org/2024/08/14-css-minutes.html fantasai<keithamus> TabAtkins: a q raised: what the `:not` pseudo class means wrt the `:host` element. The point of it being featureless is to avoid having to defensively think about what the outer page is doing with the host element <keithamus> ... should :not match everything but the host by default? <keithamus> ... not should, by default, not match the host element by default. Just like .foo wouldn't match, not(.foo) wouldn't. <keithamus> ... if you explicitly mention the host in the :not, you're explicitly opting in, so there could be a small set of rules for :not matching, compound selectors matching, complex selectors are allowed to match only if the subject compound is allowed to match <keithamus> ... this captures the notion of if the :not selector is caring about the host element. If so it is allowed to match otherwise it ignores like everything else. <keithamus> ... if this sounds reasonable I can write the edits <emilio> q+ <astearns> ack emilio <keithamus> ... I believe that brings all logical combinator pseudos into a reasonable state wrt the host eleemnt <keithamus> emilio: the only selector that would matter would be :not(:host)? Other stuff would never match effectively? <keithamus> TabAtkins: I believe so <keithamus> emilio: can we make this simpler and say it never matches? Given :host is featureless <keithamus> ... is there a use case for :not(:host)? <keithamus> TabAtkins: there are other things that could do that. Also :has(). You could potentially match a host element without :host, and if you :not that, you could potentially match the host... <keithamus> ... example: <TabAtkins> if :has(.foo) doesn't match the host (but is allowed to), the :not(:has(.foo)) would match the host <keithamus> emilio: do you really want :not(:has(.foo)) to really match? <keithamus> TabAtkins: that's the next issue <keithamus> emilio: I thought the next issue was :host(:has work <keithamus> emilio: I think I see, it's very weird. In general I dont think you can match the host with something which doesn't contain :host <keithamus> TabAtkins: that's the next issue <keithamus> astearns: Could we move forward with the complicated bits and drop them if we dont need them? <keithamus> TabAtkins: a selector X that's potentially able to match a set of elements, X and :not(X) should match all elements, which may or may not include the host. <keithamus> ... that's the underpinning I want to resolve on <TabAtkins> s/match all elements/match all those potential elements/ <keithamus> PROPOSED RESOLUTION: edit in what's described in Tabs last comment <keithamus> RESOLVED: edit in what's described in Tabs last comment |
#9509 clarified that stuff like
:is(:host)
should definitely match, due to text in https://drafts.csswg.org/selectors/#data-model:So after discussing a bit with @sesse, it wasn't super-clear to me what the expected behavior is for something like this:
I could see arguments for both behaviors:
:host
selector at all to match that host.span
nor:not(span)
match.My read of the spec is that
:not(span)
should not match, because that selector is not "a logical combination pseudo-class representing those selectors [:host
for simplicity]".I think that's my preferred behavior too, because that makes it simpler to determine "can this selector match the host" (we optimize stylesheets in shadow trees to not match a lot of the rules from the host). But ultimately I could go either way I guess.
My read of the spec doesn't match @sesse, and it seems at least the spec could get a clarification of what that "representing those selectors" means. Maybe "containing those selectors", if my read is correct, or just removing that text, if @sesse's is?
cc @tabatkins @rniwa
The text was updated successfully, but these errors were encountered: