Skip to content

[css-cascade-6] Can we support implicit scopes in nested settings? #10497

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

Closed
mirisuzanne opened this issue Jun 25, 2024 · 7 comments
Closed

[css-cascade-6] Can we support implicit scopes in nested settings? #10497

mirisuzanne opened this issue Jun 25, 2024 · 7 comments

Comments

@mirisuzanne
Copy link
Contributor

We have previously resolved to supply an 'implicit' scope-root inside <style>. The root is the parent node of the <style> element:

<article id="my-thing">
  <style>@scope { /* similar to `@scope (article#my-thing)` */ }</style>
</article>

A different implicit scope-root might be more useful when @scope is nested inside other selectors. In that case, I would expect the missing (<scope-start>) should default to (&):

article {
  /* un-scoped `article` declarations */

  @scope { /* same as `@scope (&)` */ }
  @scope to (.another-thing) { /* @scope (&) to (.another-thing) */ }
}

That isn't exactly a parallel behavior, and I'm not sure if there are edge cases where it might be unclear which is intended. But I think this would be the most useful/expected result from a nested @scope syntax.

@andruud
Copy link
Member

andruud commented Jun 26, 2024

I think it makes sense. But since it's a breaking change, we'd ideally have a use-counter before making a decision.

@mirisuzanne
Copy link
Contributor Author

@andruud could you start running that use-counter now, or should we get a resolution in advance? It seems like there's positive interest in this, and it would be worth taking to the group if we can.

@andruud
Copy link
Member

andruud commented Sep 10, 2024

should we get a resolution in advance

Yeah, I didn't manage to get a use-counter going yet, so let's get a resolution in advance. Given that the usage for @scope in general is still very low, and this change only applies to @scope as a nested group rule, I'm fairly confident that a narrower use-counter will show an acceptable number.

Also, it appears that @scope will soon be supported in all browsers, so we shouldn't wait much longer with this change.

@astearns astearns moved this to TPAC/FTF agenda items in CSSWG Agenda TPAC 2024 Sep 13, 2024
@astearns astearns moved this from TPAC/FTF agenda items to Regular agenda items in CSSWG Agenda TPAC 2024 Sep 13, 2024
@astearns astearns moved this from Regular agenda items to Thursday afternoon in CSSWG Agenda TPAC 2024 Sep 16, 2024
@tabatkins
Copy link
Member

And this should presumably use the same "same set of elements as the parent" semantic that implicit nested rules get (like .foo::before { @media (...) { color: red; } }), so pseudo-elements work properly. (Rather than literally using &, which doesn't work with pseudo-elements currently.)

@andruud
Copy link
Member

andruud commented Sep 18, 2024

@tabatkins I don't think that makes sense.

So I think & is fine here.

@tabatkins
Copy link
Member

Hm, ok. I don't want to rely on pseudo-elements never being scoping roots, but if that's currently the case then the difference would be unobservable anyway.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [css-cascade-6] Can we support implicit scopes in nested settings?, and agreed to the following:

  • RESOLVED: close this issue, no change unless better arguments
The full IRC log of that discussion <dbaron> ScribeNick: matthieud
<matthieud> miriam: previously we creating implicit @scope root without a prelude-start
<matthieud> miriam: the parent node is the implied scoping root
<matthieud> do we want to have the similar implicit behavior in a style rule nested context ?
<ydaniv> q+
<astearns> ack ydaniv
<matthieud> ydaniv: what if it's not nested ?
<matthieud> miriam: we allow non nested & selector which resolve to root, could be the same
<astearns> ack fantasai
<matthieud> fantasai: when no scope-start, it uses the closest node at the scoping root
<matthieud> fantasai: with this resolution, we will longer be able to reference this implicit scoping root
<fantasai> s/longer/no longer/
<matthieud> miriam: the confusion is if you are in a style element in the doc, with an implicit @scope non nested and one nested inside a style rule, they don't have the same scoping root anymore which could be surprising
<ydaniv> q+
<fantasai> Example is
<matthieud> ydaniv: it's useful to have this functionality
<fantasai> <section><style>@scope { ... }</style> ...</section> vs <section><style>@Style (&) { ... }</style> ...</section.
<matthieud> miriam: there is no way to get back the parent node if we adopt this resolution
<matthieud> ydaniv: we could have a new keyword
<matthieud> fantasai: there are other situation where & and :scope don't represent the same element
<fantasai> s/fantasai/miriam/
<matthieud> PROPOSED SOLUTION: close this issue, no change unless better arguments
<matthieud> RESOLVED: close this issue, no change unless better arguments
<fantasai> s/better arguments/arguments for stronger than those against/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Thursday morning
Development

No branches or pull requests

5 participants