-
Notifications
You must be signed in to change notification settings - Fork 711
[css-cascade-5] Do conditional rules impact layer order? #6407
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
Comments
/cc @xiaochengh |
In isolation I like the bubbling suggestion. But I wonder if it's too great an "exception" to how conditionals usually work, and whether adding such special-snowflake behaviors actually end up more surprising. In your latest example, re-ordering based on viewport width just looks like what the author is asking for to me. :-) There are other options though:
|
I think there are two questions here:
It seems really broken to me that layers can be conditionally re-ordered. And what's the use case?
I prefer the bubbling option, which looks the simplest to me. |
I don't think we really can disallow layers inside media (parse error), or even apply the styles without contributing to layer-order. Sites sometimes use an html media attribute on most or all linked stylesheets (eg @tabatkins also pointed out that once we allow layers inside conditional styles, we can't entirely avoid the dynamic behavior. Browsers often lazy-load stylesheets with an unmatched media attribute. If the media eventually matches, and those styles load late, either approach (always apply, or dynamically apply-on-match) will need to apply those changes once the sheet has loaded. That may be an argument for embracing the dynamic behavior, and making it the spec default. If we do go that rout, though, we would need a special case for container queries, which do not have any global "matched" state. |
To summarize all of the options, and their implications:
|
Fully dynamic for |
The CSS Working Group just discussed
The full IRC log of that discussion<Rossen_> topic: https://github.com//issues/6407<Rossen_> github: https://github.com//issues/6407 <TabAtkins> miriam: what happens when layers are defined inside of conditionals? <TabAtkins> miriam: like @media ... { @layer ...; } <TabAtkins> miriam: Do those layers contribute to layer order, and if so, how? <TabAtkins> miriam: In the final thread comment i listed the options <TabAtkins> miriam: First is parse error - don't think that works. <TabAtkins> miriam: Like what happens when we apply a media to an entire stylesheet? Doesn't seem right to ahve layers disappear. <TabAtkins> miriam: Second is layers in conditionals don't contribute to the order. This has similar issues - what if a layer *only* appears inside a conditional? Still need some order for them. <TabAtkins> miriam: So remaining is (3) layers always contribute in order they appear, whether the conditional is matched or not <TabAtkins> miriam: I think this is my favorite solution, bc it doesn't require special casing <TabAtkins> miriam: Last solution is to make layer ordering dynamic based on conditionals <TabAtkins> miriam: In some ways this is true already via (3) with media="" attribute, due to lazy-loading, so you'll get some dynamic behavior anyway <TabAtkins> miriam: This would just go all the way <TabAtkins> miriam: It'll need special casing for container queries; they don't have a global match state, they're matched per element. They'd have to fall back to the first or second option there. <TabAtkins> TabAtkins: I was originally for option 3, but lazy loading made me reconsider, so now I'm strong for option 4 (with ignoring layers in @container rules) <TabAtkins> TabAtkins: And emilio was also for 4 on Twitter, and it looks like Anders is for 4 from the issue thread <TabAtkins> miriam: The Twitter thread also voted for 4 by far. (Not always right, but it's useful info about what authors expect.) <futhark> q+ <TabAtkins> miriam: I think 3 is simpler to udnerstand and teach, but I see the points for 4. <TabAtkins> miriam: Fine with either way. <Rossen_> ack futhark <TabAtkins> futhark: NOt just lazy loading, also inserting stylesheets and rules. You can insert layer rules dynamically, right? <TabAtkins> miriam: yeah <TabAtkins> futhark: So I think that leans toward fully dynamic as well, since other things cause similar dynamic results <TabAtkins> Rossen_: So I'm hearing pretty strong support for 4 among authors and impls. Are you okay with that, Miriam? <bkardell_> +1 <TabAtkins> miriam: sure <TabAtkins> Rossen_: Any objections? <TabAtkins> RESOLVED: Layer rules respect conditionals, and are ignored in non-global conditionals. |
The CSS Working Group just discussed The full IRC log of that discussion<Rossen_> topic: https://github.com//issues/6407<TabAtkins> github: https://github.com//issues/6407 <TabAtkins> miriam: So inside of @container, layers can't contribute to order. <TabAtkins> miriam: Is that a parse error? (layer rules inside of @container is always invalid) <TabAtkins> miriam: Or is it only an error to *introduce* a layer inside of one, and it's fine to use one that's already defined? <TabAtkins> futhark: I'll need more time to think <TabAtkins> TabAtkins: Assuming layered styles are okay inside of container queries generally (I think so, but futhark can correct), then I suggest if a @layer is *introduced* in a @container, it's treated as always being introduced there, regardless of the @container matching or not. <TabAtkins> futhark: Need some more time to think on the consequences of this <TabAtkins> miriam: It's basically option 3, but applied only to container queries <TabAtkins> Rossen_: So doesn't sounds like we have resolution yet, we'll take the rest of this topic to github |
@tabatkins said: "Assuming layered styles are okay inside of container queries generally (I think so, but futhark can correct), then I suggest if a @layer is introduced in a @container, it's treated as always being introduced there, regardless of the @container matching or not." I agree. |
I agree. I'll begin drafting that language, and we can bring it back to the group for a formal resolution (pending further feedback). |
Proposed resolution: If a layer is introduced in a non-global condition like @container, it's added to the layer order as though the condition is true. |
The CSS Working Group just discussed
The full IRC log of that discussion<fantasai> Topic: Cascade 5<chris> fantasai you will do the transition request? <fantasai> github: https://github.com//issues/6407 <fantasai> miriam: Question was about defining layers defined inside global conditions like @media <fantasai> miriam: but open issue about non-global condition like container queries <florian> s/fantasai you will do the transition request?// <fantasai> miriam: Thread concluded should always affect layer order <fantasai> TabAtkins: Looks good <fantasai> emilio: How do auto-conditionals behave inside container queries? <fantasai> emilio: Is there a real use case for this? <fantasai> miriam: If you want some of the things in the container query to be layered or not <TabAtkins> fantasai: the clarification here is that there's no particular use-case for the layer existing or not conditionally, but there is a use-case for having layered styles in there, so we ahve to define it <fantasai> emilio: Unfortunate to have to traverse everything <fantasai> emilio: when building data structure, when finding media/supports query that doesnt' match <fantasai> emilio: just skip all the rules <fantasai> emilio: but here you are forced to read all the rules on the page <fantasai> miriam: you have to do that anyway, because container queries aren't global, you have to read them to understand the page <fantasai> TabAtkins: I think emilio misunderstood <fantasai> TabAtkins: in global conditionals, they are conditional <fantasai> emilio: Oh, I thought we were reverting on that. No, this makes sense. <fantasai> astearns: Other comments on this? <fantasai> astearns: If layer is introduced in a container query rule, it always affects layer order, whether or not that query matches anything <fantasai> miriam: more broadly, any non-global condition <fantasai> astearns: Any other non-globls? <fantasai> miriam: Not yet <fantasai> astearns: Adding that as the reason for this requirement would probably help future spec development, so add editorially <fantasai> RESOLVED: If a layer is introduced in a non-global conditional rule (such as a container query), it always affects the layer order, whether or not that query matches |
In CSS Cascading & Inheritance L5 we define the
@layer
rule, and the way layers "stack" in priority based on the order they are first encountered. These will stack so the higher numbers override the lower numbers:In general, layers should interact well with conditional rules. In isolation these two rules should mean the same thing:
If the media-condition is true, then the styles are applied in the specified layer (
one
). But it's a bit less clear how the second example (layer inside condition) should impact the order of multiple layers:Does layer
one
come first, last, or does it update dynamically based on the evaluation of the condition? I think the two options are roughly:This question is also relevant to other conditions, such as
@supports
or@container
.The text was updated successfully, but these errors were encountered: