Skip to content

[selectors] Should :not(foo) match the host of the shadow tree? #10179

Description

@emilio

#9509 clarified that stuff like :is(:host) should definitely match, due to text in https://drafts.csswg.org/selectors/#data-model:

A featureless element does not match any selector at all, except those it is explicitly defined to match (and logical combination pseudo-classes representing those selectors).

So after discussing a bit with @sesse, it wasn't super-clear to me what the expected behavior is for something like this:

<!doctype html>
<div id="host" style="color: blue">
  <template shadowrootmode="open">
    <style>:not(span) { color: green !important }</style>
    What color is this text?
  </template>
</div>

I could see arguments for both behaviors:

  • On one hand, it feels very unexpected that something that doesn't contain a :host selector at all to match that host.
  • But on the other hand, it feels weird that neither 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Unsorted

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions