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] Interaction with :host is unfortunate. #9509

Closed
emilio opened this issue Oct 21, 2023 · 6 comments
Closed

[css-nesting] Interaction with :host is unfortunate. #9509

emilio opened this issue Oct 21, 2023 · 6 comments
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-nesting-1 Current Work

Comments

@emilio
Copy link
Collaborator

emilio commented Oct 21, 2023

This test-case (live) doesn't produce the expected behavior (purple) in any browser:

<!doctype html>
<div id="host">Something</div>
<script>
  host.attachShadow({ mode: "open" }).innerHTML = `
    <style>
      :host {
        background-color: green;
      }
      div {
        background-color: red;
        display: inline-block;
        width: 12px;
        height: 12px;
      }
      :host(#host) div {
        background-color: blue;
      }
      :host(#host) {
        div {
          background-color: purple;
        }
      }
    </style>
    <slot></slot>
    <div></div>
  `;
</script>

This is because per spec, the host only matches featureless :host selectors, and the & (or :is(:host(..)) for that matter) isn't that.

This is similar to #9153 / #9492 (cc: #8738).

cc: @tabatkins @andruud @mdubet @LeaVerou @fantasai

@tabatkins
Copy link
Member

That's an impl bug. The spec supports this case.

For &:

The nesting selector is capable of matching featureless elements, if they were matched by the parent rule.

For :is(:host):

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).

@tabatkins tabatkins added css-nesting-1 Current Work Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. labels Oct 21, 2023
@emilio
Copy link
Collaborator Author

emilio commented Oct 21, 2023

We should add tests, though that's a bit complicated impl wise (at least in Firefox), because you need not to match all other selectors inside :is().

@emilio
Copy link
Collaborator Author

emilio commented Oct 21, 2023

@tabatkins my read about your second quote is that :is(:host) should match but :is(#foo, :host) shouldn't, is that right? If so that simplifies the implementation significantly.

@emilio
Copy link
Collaborator Author

emilio commented Oct 21, 2023

(That means that nesting inside foo, :host would not work as expected perhaps, but that seems more edge-casey than just nesting inside :host)

@tabatkins
Copy link
Member

No, I'd expect :is(#foo, :host) to match, just like #foo, :host would. That's the point of that line.

@andruud
Copy link
Member

andruud commented Oct 23, 2023

Yes, I've been wanting to fix this for a while in Blink. In our (implementations') defense, :is() not matching the host was the correct behavior at the time. The spec was changed later. :-)

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Oct 27, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Oct 28, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1850974
gecko-commit: 3b13b5585380e95b76444f10d65a42d3543bbd1a
gecko-reviewers: zrhoffman
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 30, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

UltraBlame original commit: 3b13b5585380e95b76444f10d65a42d3543bbd1a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 30, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

UltraBlame original commit: 3b13b5585380e95b76444f10d65a42d3543bbd1a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 30, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

UltraBlame original commit: 3b13b5585380e95b76444f10d65a42d3543bbd1a
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 1, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1850974
gecko-commit: 8b16994e8df5ba96e720e00a4f0289fdb3a83708
gecko-reviewers: zrhoffman
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Nov 2, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570
aosmond pushed a commit to aosmond/gecko that referenced this issue Nov 2, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 2, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1850974
gecko-commit: 8b16994e8df5ba96e720e00a4f0289fdb3a83708
gecko-reviewers: zrhoffman
ErichDonGubler pushed a commit to ErichDonGubler/firefox that referenced this issue Nov 2, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Nov 8, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

UltraBlame original commit: 8b16994e8df5ba96e720e00a4f0289fdb3a83708
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Nov 8, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

UltraBlame original commit: 8b16994e8df5ba96e720e00a4f0289fdb3a83708
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Nov 8, 2023
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570

UltraBlame original commit: 8b16994e8df5ba96e720e00a4f0289fdb3a83708
github-actions bot pushed a commit to Loirooriol/stylo that referenced this issue Mar 17, 2024
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570
github-actions bot pushed a commit to Loirooriol/stylo that referenced this issue Mar 17, 2024
This should work per spec, see
w3c/csswg-drafts#9509.

Tweak a bit the selector flags set up so that checking for :host
selectors during CascadeData rebuilds is cheap.

Differential Revision: https://phabricator.services.mozilla.com/D191570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-nesting-1 Current Work
Projects
None yet
Development

No branches or pull requests

3 participants