Re: [csswg-drafts] [css-cascade] Cascade layers need an import syntax (#5681)

The CSS Working Group just discussed `[css-cascade] Cascade layers need an import syntax`, and agreed to the following:

* `RESOLVED: Cascade layer imports is done using @import followed by URL followed by layer declaration`

<details><summary>The full IRC log of that discussion</summary>
&lt;Rossen_> Topic: [css-cascade] Cascade layers need an import syntax<br>
&lt;myles> ScribeNick: myles<br>
&lt;Rossen_> github: https://github.com/w3c/csswg-drafts/issues/5681<br>
&lt;myles> miriam: We have this in the spec as an option for how you write the @layer rule. You can include a URL in the layer. In @layer, and it it works similar to an import. But there have been questions about whether we should instead extend the existing import to allow layer names, or even come up with a 3rd option.<br>
&lt;myles> miriam: A new import layer rule that is different from @layer or @import.<br>
&lt;myles> miriam: What's in the spec now is @layer can take a URL.<br>
&lt;Rossen_> q?<br>
&lt;myles> Rossen_: ok.<br>
&lt;myles> Rossen_: Is that the current proposed syntax... do you just want feedback from the group?<br>
&lt;myles> miriam: Some people had a preference for extending @import. I don't have strong feelings on this. I think it works nicely to keep it all in @layer. We'll need to allow @layer before @import because it's important that layer names are able to be established early.<br>
&lt;bkardell_> I also don't have strong feelings, but I like @import'ing being import I guess<br>
&lt;myles> Rossen_: How does @layer differ from @import?<br>
&lt;myles> miriam: @layer imports a stylesheet into a layer. It allows you to add layering while you're imorting<br>
&lt;myles> fantasai: @import doesn't establish any layers. It just puts rules into the stylesheet as if they are inlined. @layer creates a layer for things inside it, but doesn't inline them. In theory we can say @layer can take @import inside the nested block, but then you have to deal with the fact that @import has to be the first thing in the stylesheet, so it's complex. So the syntax should be "this statement creates a layer and imports a stylesheet into<br>
&lt;myles>  it" as if it was @layer with an @import inside it.<br>
&lt;Rossen_> q?<br>
&lt;myles> fantasai: do we use @import with extra syntax? Or do we allow @layer to take a URL instead of a block of rules.<br>
&lt;emilio> q+<br>
&lt;jensimmo_> q=<br>
&lt;jensimmo_> q+<br>
&lt;myles> florian: Sticking to @layer is better. 3 variants: @layer name;, @layer layername {...}, @layer layername url. There is symmetry between 3 variants.<br>
&lt;myles> florian: It's self-contained and clean.<br>
&lt;bkardell_> q+<br>
&lt;Rossen_> ack emilio<br>
&lt;myles> emilio: would that layer syntax have the same restrictions as @import? For appearing before other rules?<br>
&lt;myles> fantasai: yes.<br>
&lt;myles> emilio: *not* doing that means we have to teach prescanners.<br>
&lt;myles> fantasai: It's defined as it has the same placement as @import.<br>
&lt;Rossen_> ack jensimmo_<br>
&lt;myles> emilio: it's ok then<br>
&lt;myles> jensimmo_: It's convenient for authors to put it anywhere, though<br>
&lt;myles> fantasai: @layer name {...} can go anywhere. @layer name url can only go at the top.<br>
&lt;myles> jensimmo_: @layer name url might not need restrictions, which would be valuable<br>
&lt;myles> astearns: Maybe we should use @import for that case, then, to make the restrictions simpler<br>
&lt;myles> fantasai: We already have precdent for putting @layer anywhere. IT's just the one with {} can go anywhere. I'm leaning to have all 3 have the saem syntax for consistency. Because otherwise we would have 2 placement rules, which would be weird.<br>
&lt;Rossen_> q?<br>
&lt;myles> bkardell_: i don't understand something.<br>
&lt;fantasai> s/{} can go anywhere/{} can only go after any importing rules/<br>
&lt;myles> bkardell_: In "other options" there is @layer reset with a nested import. Does emilio's comment mean it's not possible?<br>
&lt;myles> emilio: Please let's make it not possible<br>
&lt;myles> bkardell_: Let's remove that as an option then<br>
&lt;myles> bkardell_: So the options are using @layer or using @import. that's it.<br>
&lt;myles> bkardell_: I'd like @import to be about importing, and having a special version of import which can also create a layer. But I don't have strong feelings.<br>
&lt;Rossen_> q?<br>
&lt;Rossen_> ack bkardell_<br>
&lt;myles> fantasai: This is a naming discussion.<br>
&lt;myles> Rossen_: Yes and but it feels like a bit more. @import is already rather understood and well-used by the community.<br>
&lt;myles> Rossen_: Having yet another mechanism to import seems odd.<br>
&lt;myles> florian: We're having yet another mechanism to import anyway. We're just discussing syntax.<br>
&lt;myles> Rossen_: Explicitly yes.<br>
&lt;astearns> either one is fine by me - slight preference for @import<br>
&lt;myles> Rossen_: Alright, so. Let's try to move this forward and get to a conclusion. Most people were in favor of @layer. A few who prefer @import to be used for import: namely: bkardell_ and Rossen_ . But for me it's just a preference; I can live with @layer.<br>
&lt;myles> bkardell_: You articulated the way i feel. I feel like people understand the limits of @import, and we have machinery to do those limits already. Playing into that is goodl.<br>
&lt;myles> emilio: Another benefit of @import is we don't have to come up with OM thing to hold stylesheets. I lean toward re-using @import<br>
&lt;myles> astearns: We need OM changes anyway<br>
&lt;myles> emilio: We need to change the conditon. We have a proposal for @import-supports. So we need to expose that "import conditoin" or "import layer" but that seems like an easier change than exposing a CSS layer rule that may have a URL or not, and may have an inner block or not, or inner stylesheet or not.<br>
&lt;myles> Rossen_: That was the motivation behind my preference as well. They have the same behavior from importing POV. In the future, when we extend @import, we have to make a parallel change in something else too.<br>
&lt;myles> emilio: That's a good point. We have proposals for @import-cross-origin to maek cross-origin requests. WOuld be good to not duplicate<br>
&lt;myles> TabAtkins: I agree, and am strongly for using @import.<br>
&lt;jensimmo_> q+<br>
&lt;myles> florian: There are variants. @import layer (name url). Or @import url as layername. Which is more readable, but couldn't deal with unnamed layer (unless we add a new keyword meaning "import as unnamed") which wouldnt' mean "import into the layer named 'unnamed'" but instead "import into unnaemd ...."<br>
&lt;argyle> https://github.com/w3c/csswg-drafts/issues/5681#issuecomment-755513963<br>
&lt;myles> Rossen_: what are you talking about<br>
&lt;myles> florian: Una suggested something that seems both more readable and not working in the unnamed layer case.<br>
&lt;florian> @import layer reset url(reset.css);<br>
&lt;florian> @import layer(reset) url(reset.css);<br>
&lt;florian> @import url(reset.css) as layer;<br>
&lt;Rossen_> q?<br>
&lt;argyle> `@import reset from url(reset.css) as layer;`?<br>
&lt;myles> jensimmo_: There are 2: one is to add another keyword or whatever it's called to the import statement to say which layer it goes to, and the other which is about nesting @layer reset (@import url). I keep going back and forth. THere's something about how clear it is that you start a layer, when you define a layer, you import a stylesheet. THat's appealing. But I also understand the keyword would still work well.<br>
&lt;Rossen_> ack jensimmo_<br>
&lt;myles> jensimmo_: I'm leaning toward nesting.<br>
&lt;myles> Rossen_: Now we're swinging the other way.<br>
&lt;Rossen_> @import layer reset url(reset.css); @import reset url(reset.css) as layer; @import layer(reset) url(reset.css);<br>
&lt;myles> fantasai: My preference would be for whatever syntax we choose to have the word "layer" in there somewhere. We need a way to have unnamed layers for parallelism. MOst of the parameters for our @import rules come after the @import rules (conditions, parsing) is a little bit open-ended. It might make more sense to do this before the URL and it also brings up tot he front and makes it obvious "we are making a layer with this URL". SO my preference is<br>
&lt;myles>  one of the earlier options.<br>
&lt;myles> Rossen_: I pasted the 3 variants that are in the issue.<br>
&lt;myles> jensimmo_: por que no los dos?<br>
&lt;myles> Rossen_: &lt;lists the 3 options verbally><br>
&lt;myles> emilio: Can we add a 4th one? @import url something something layer(something)<br>
&lt;myles> emilio: reasoning: that's how the extra things to @import work already. like media queries.<br>
&lt;myles> fantasai: THat would parse as an invalid media query, and it would get imported anyway whether or not you support layer<br>
&lt;Rossen_> @import url(reset.css) as layer(reset)<br>
&lt;myles> emilio: We have that issue for the proposed @supports function, right. I'd like to have the mandatory parts at the front, like @import url, then the optional stuff like the conditions<br>
&lt;myles> Rossen_: where does the @support go in this case.<br>
&lt;astearns> what was the 'both' you were asking about, jensimmo_ ?<br>
&lt;fantasai> https://www.w3.org/TR/css-cascade-4/#conditional-import<br>
&lt;myles> emilio: I think we resolved on this at the end, but it's not in the spec. It goes where the media query goes. Which is weird cause you text can mean either<br>
&lt;myles> Rossen_: Without dumping the whole issue into this one, wasn't the issue to have @supports evaluated so you're not hitting the network? The current solution is to have @supports at the end?<br>
&lt;fantasai> https://www.w3.org/TR/css-cascade-4/#at-import<br>
&lt;myles> emilio: yes. We added an @supports function.<br>
&lt;fantasai> Current syntax is @import [ &lt;url> | &lt;string> ]<br>
&lt;fantasai>         [ supports( [ &lt;supports-condition> | &lt;declaration> ] ) ]?<br>
&lt;fantasai>         &lt;media-query-list>? ;<br>
&lt;jensimmo_> Could we do `@import layer(reset) url(reset.css);` AND `@import url(reset.css) layer(reset) ;` AND @layer reset {<br>
&lt;jensimmo_> @import url(reset.css); }<br>
&lt;myles> emilio: With the function syntax it's possible. You just determine if it's this function or not, and if it's not, then assume it's something else.<br>
&lt;myles> jensimmo_: What is the precise syntax for namign the layer? I like haivng layer() and reset. THat would allow us to use layer with 2 parens and no name and leave it blank to do what fantasai was metnioning to assign it to a named layer without it being too messy. And having the name of the layer an argument to a function, it might not matter which name comes first<br>
&lt;myles> jensimmo_: I also was trying to say, would it be possible to do an import statement with a way to namet eh layer *and* CSS does both so authors cna pick which ever way they want to do it, or and the nested @layer { @import ... }<br>
&lt;Rossen_> q?<br>
&lt;Rossen_> ack f<br>
&lt;florian> q+<br>
&lt;myles> fantasai: My concern with the nested one is you'd be tempted to put declarations there. IN theory you could do that once, but then you coudln't put further @import rules. So then you 'd have @layer blocks which don't include any declarations, and if you do, then it becomes invalid, so it will be confusing. I dont' want to give the author the impressino they can put rules in the block. they can't do that.<br>
&lt;TabAtkins> @import currently has a req that it comes first in a file, which lets impls pretend that the imported files are ordered fully before its importing file (they dont' have to track nesting of imports for purpose of figuring out source order of declarations)<br>
&lt;Rossen_> ack f<br>
&lt;myles> florian: Assuming we go with @import, esp. for extension ability. It shouldn't be after the rule. Because it's syntactically ambiguous with media queries. We don't want something to parse both as a layer and as a media query, that's bad<br>
&lt;myles> emilio: we already do that with supports, right?<br>
&lt;fantasai> Also, everything after the URL is currently a condition. This isn't a conditional.<br>
&lt;TabAtkins> @layer { @import} doesn't impose this restriction.<br>
&lt;myles> emilio: fantasai pasted the supports syntax now. It would only be ambiguous if you add a layer() function into media queries. but not otherwise<br>
&lt;myles> florian: But supports and layer are conditional things, they belong in roughly the same place, so i'm still uncomfortable with thtat, but less so<br>
&lt;myles> emilio: I don't mind much either way. It would be slightly nicer, given all browsers have bespoke @import preload parseing, and scan for literally "@import string" and then preload that, I would be slightly happier if we didn't have to add harder parsers, because that code is pretty ugly already.<br>
&lt;myles> emilio: I don't know.<br>
&lt;myles> Rossen_: Let's try to resolve.<br>
&lt;fantasai> Wouldn't you want your speculative loader to parse conditions on the @import?<br>
&lt;myles> Rossen: Let's try to record a resolution here. It will be easier to revisit the specific syntax of where the layer declaration goes if we're not happy with it later, but at least it seems we're all leaning toward where the declaration goes with @import.<br>
&lt;myles> Rossen: emilio, your proposal is @import url layerstuff?<br>
&lt;myles> emilio: &lt;silence><br>
&lt;myles> Rossen: Is that something we can start working with?<br>
&lt;myles> s/emilio: &lt;silence>/emilio: yes/<br>
&lt;emilio> fantasai: yeah, that is right (I think right now we just don't preload conditional stuff)<br>
&lt;jensimmo_> @import url(reset.css) [layer stuff];<br>
&lt;myles> RESOLVED: Cascade layer imports is done using @import followed by URL followed by layer declaration<br>
&lt;jensimmo_> @import url(reset.css) layer(reset) ;<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5681#issuecomment-777868916 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 11 February 2021 23:41:06 UTC