-
Notifications
You must be signed in to change notification settings - Fork 639
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
[cascade-6] Unclear proximity for scoped descendant combinator #8380
Comments
Yeah, it kinda sounds like the specificity problem from #1027. Example: .a ~~ .b >> .c {} <div class="a" id="a1"></div>
<div class="b" id="b1">
<div class="a" id="a2"></div>
<div></div><div></div><div></div><div></div><div></div><div></div>
<div class="b" id="b2">
<div class="c"></div>
</div>
</div> If we match The 2nd option seems better, but this means that, in order to know the precedence of a selector, it can't just be matched greedily, all possible matchings need to be considered. |
@andruud Can you clarify why the other scope notations don't have this issue? Is it just a clearer order of operations - matching scope root/boundary elements, and then resolving each selector in relation to those defined scopes? I think it's likely we'd want to go with the more clear syntax if they have the same meaning, but just as a way of understanding the issue – does it help to parse |
Right, my understanding of the intention of the scoping combinators is that they're functionally sugar for a set of (possibly nested) |
Thanks for that context and info @Loirooriol. Not being able to finish selector matching at the first match is pretty much unacceptable. (Though maybe this problem is only possible to create if we add
Nested
OK, if
|
If we do with plain 'syntax sugar', I think you would basically treat each mention of
To highlight the two questions raised here: Nesting Scopes, Generally: To make sure I understand what's implemented: When I think that might be a reasonable solution, and certainly the easiest one to reason about. If we wanted, I think there might be ways to expand that and give some priority to things that are 'scoped more often' – but I'm not sure that's helpful, or actually captures a useful heuristic. But that probably needs more clarity in the specification. Sugaring Limits: It seems like the other issue here is that a scope-start clause in the (I'd be tempted to drop any scope selector sugar from v1 of the spec, and return later to see if it's necessary) |
I still don't think that's clear. @sibling-scope (.a) {
@scope (.b) {
.c { color: blue }
}
} <div class="a"></div>
<div class="b" id="b1">
<div class="b" id="b2">
<div class="c"></div>
</div>
</div> Does it mean that the rule will not apply, since the closest |
@mirisuzanne My point with (2) vs (3) was that they can not both expand to effectively the same For example, the The
Yes, exactly. I did not see anything in https://drafts.csswg.org/css-cascade-6/#scope-atrule that would suggest anything else.
It should be completely uncontroversial in terms of performance, and if it's easy to reason about I guess that's something authors will appreciate as well. The question is if it's "too simple" from the author's perspective, i.e. would proximity still be useful enough in more complicated (nested) scoping scenarios? (I can't answer this question). |
@Loirooriol Using the "nearest scope is what determines proximity" mode, I suppose your example would go like this:
(Unless I've misunderstood how |
That's how I would parse the example as well. Nested scope-start rules are (according to spec already) scoped by any parent scope rules. So
Right. Yeah, that's a more difficult logic to impose on a combinator.
In my mind proximity is a useful heuristic in the simple cases - and this logic continues to handle those cases well. Once things get more complicated, authors will likely need to think about other cascade controls: layers, specificity, etc. With a heuristic like this, I think it would be a mistake to get too clever about solving more complex scenarios in an abstract or magical way. |
I mean, the equivalent
That does match the identical set of elements. The only significant thing is the fact that you can write something like |
Then how about the following:
|
We've already resolved to remove the selector scoping notation - so don't need to do anything there, except apply the changes. I like this proposed resolution. Add to telecon or async agenda? |
Don't necessarily need a resolution at all - the spec is FPWD. As long as it's not expected to be controversial (and from this thread, it shouldn't be), you can just do it. |
If only one |
No need for it, I'd think? We allow nested Like, additional |
Sure that's possible, but failing loud may be less confusing than failing silently. If they are invalid inside |
Inside |
The current spec text says about the combinator that:
We defined it that way to avoid having @scope (.a) {
.b >> .c :scope { ... }
} We could de-sugar directly, leaving @scope (.a) {
@scope (.b) {
.c :scope { ... }
}
} In that case On the other hand, if we don't want the combinator to update the meaning of (I'm somewhat drawn to the conclusion that these combinators introduce more authoring complexity than they solve, and we should at remove or defer to another level, so they don't block shipping a more clear at-rule syntax) |
The alternative to all of that is: we don't need strict de-sugaring - just clarification that proximity is determined:
With normal |
My hope is that we can resolve on that the proposal in my previous comment. Failing that, I might push to defer scoped combinators to a future level, so they don't hold up the main |
+1 to Tab's comment in #8380 (comment) and Miriam's clarification that it's not a strict de-sugaring (to handle cases where that doesn't quite work). But about matching only the last step:
I'm actually surprised by this. I think it's pretty confusing if you have
and the color is yellow for an element that matches both. |
I don't think it would be, at least if we accept the implied descendant relationship proposed in #8377. If x is inside b, which is inside a - x will have a closer proximity to b, and the color will be blue. |
Well, it's still possible for it to be yellow, if there's another instance of A between the B and the X. But assuming there's only one A and B, then yes, it'll definitely be blue, since the B defaults to being inside the A (and thus is closer to the X). |
Right. The case where scope
I don't see any reason to have a specificity-like cascade mechanic based on 'how many scopes were used to get here'. That would over-complicate what scope is about. |
In simple cases (e.g.
A >> B
), it's clear what this means, but what about more complex cases?A >> B >> ... >> Z
,A:has(B >> C)
,:is
,:not
?It doesn't seem easy to spec an easily understandable behavior for
>>
given the amount of flexibility we have in selectors. Perhaps we should revisit whether>>
really is needed at all.If we do keep it, we should avoid introducing complexity that would be detrimental to performance:
:is(X,Y)
which matches for both X and Y but with different proximities). Once we find a match, we can not continue looking for "better" matches.Note: The proposed selector scoping notation does not have any of these issues, so perhaps we should continue to explore that direction instead, if we really want "inline" scoping.
The text was updated successfully, but these errors were encountered: