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-cascade-6] clarification of :scope matching in nested scopes #9741

Closed
kizu opened this issue Dec 21, 2023 · 5 comments
Closed

[css-cascade-6] clarification of :scope matching in nested scopes #9741

kizu opened this issue Dec 21, 2023 · 5 comments
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-cascade-6

Comments

@kizu
Copy link
Member

kizu commented Dec 21, 2023

While testing different ways scopes interact when being nested, and how :scope behaves inside them in both Chrome and Safari Technology Preview, I found a difference in how the browsers treat the :scope when there are nested scopes present.

Here is a CodePen with the example: https://codepen.io/kizu/pen/xxBxKao

HTML & CSS for this example
<div class="outer">
  <div class="inner">
    <div class="test">this should be lightgreen</div>
    <div class="test never">this should be lightgreen</div>
    <div class="test unwrapped">this should be lightgreen</div>
  </div>
</div>
@scope (.outer) {
  .test {
    background: red;
  }
  
  @scope (.inner) {
    :scope.inner .test {
      background: lightgreen;
    }
    
    /* This should never match */
    :scope.outer .test.never {
      background: tomato;
    }
  }
}

@scope (.outer .inner) {
  :scope.inner .unwrapped {
    background: lightgreen;
  }
}

I consider the way it works now in Chrome (the :scope matches the innermost closest defined scope) as correct. I did not find anything in the specs (https://drafts.csswg.org/css-cascade-6/#scope-scope) outside example 8, which shows the scope equivalence, where the :scope matches the inner scoping root.

Given how Safari currently uses the topmost scoping root instead, I think it would be nice to clarify the behavior of the :scope inside nested scopes explicitly in the normative parts of the spec, so there will be less left for interpretation.

@andruud
Copy link
Member

andruud commented Jan 11, 2024

I consider the way it works now in Chrome (the :scope matches the innermost closest defined scope) as correct.

This was behavior was always the intent, we just need an editorial change here IMO.

@bramus
Copy link
Contributor

bramus commented Jan 12, 2024

This was addressed in 180fce4, no?

… the [=scoping root=] is defined by the innermost ''@scope''.

@mirisuzanne mirisuzanne added this to Discussions in Cascade 6 (Scope) Jan 24, 2024
@mdubet
Copy link

mdubet commented Jan 31, 2024

The spec, Chrome and Safari all seem to have the same behaviour here (:scope matches the scoping root of the innermost @scope)

@astearns astearns added this to Unsorted regular in Feb 2024 Agenda Feb 8, 2024
@mirisuzanne
Copy link
Contributor

It seems like we might be able to close this as a browser bug that's been fixed (question answered)? I'm not sure we need any resolution. @fantasai you added the agenda+ label - was there something more that needed discussion on this?

@kizu
Copy link
Member Author

kizu commented Feb 27, 2024

Testing it in the latest Safari TP — it seems things now behave the same as in Chrome, and the spec edit seems sufficient, so it is ok to close this issue and remove from the agenda.

@astearns astearns removed the Agenda+ label Feb 27, 2024
@mirisuzanne mirisuzanne added the Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. label Feb 27, 2024
@mirisuzanne mirisuzanne moved this from Discussions to Done in Cascade 6 (Scope) Feb 27, 2024
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-cascade-6
Projects
Feb 2024 Agenda
Unsorted regular
Development

No branches or pull requests

7 participants