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-5] @layer preceding @import should be valid #8670

Closed
cdoublev opened this issue Apr 3, 2023 · 2 comments
Closed

[css-cascade-5] @layer preceding @import should be valid #8670

cdoublev opened this issue Apr 3, 2023 · 2 comments

Comments

@cdoublev
Copy link
Collaborator

cdoublev commented Apr 3, 2023

According to 2. Importing Style Sheets: the @import rule, @import can precede @layer statement.

Any @import rules must precede all other valid at-rules and style rules in a style sheet (ignoring @charset and @layer statement rules) [...]

But it is not clear if it can be preceded by @layer statement (emphasize added):

[...] and must not have any other valid at-rules or style rules between it and previous @import rules

What are these other valid at-rules or style rules? Do they include @charset and @layer statements?

I guess @import can now be preceded by @layer based on 6.4.4.2. Declaring Without Styles: the @layer statement at-rule:

Such empty @layer rules are allowed before @import and @namespace rules


Aside: I think that enumerating at-rules and style rules may not seem necessary and may be simplified to rules.

Any @import rules must precede all other valid rules (ignoring @charset and @layer statement rules) and must not have any other valid rules (ignoring @charset and @layer statement rules) between it and previous @import rules, or else the @import rule is invalid.

@cdoublev
Copy link
Collaborator Author

cdoublev commented Apr 3, 2023

I found #6522. Based on its resolution, interleaving @layer statement between @imports, or interleaving @import between @layer statements, must be invalid. The current prose and Example 31 seem confusing then.

It’s also possible to have @import rules help establish the order, by placing them between @layer rules. This example will have the same result:

@layer default;
@import url(theme.css) layer(theme);
@layer components;

@layer default {
  audio[controls] {
    display: block;
  }
}

And it seems to also apply to interleaving @layer between @namespace statements, or vice-versa, as explained in this non-normative note:

Note: Any @layer rule that comes after an @import or @namespace rule will cause any subsequent @import or @namespace rules to be ignored.

Actually, this means you can declare @layer, @import, @namespace, in this order, but not @import, @layer, @namespace. I am confused.


Aside (another simplification suggestion):

Such empty @layer are allowed before @import and @namespace rules (after the @charset rule, if any) as well as everywhere @layer block at-rules are allowed.

@charset is always ignored by the parser, according to CSS Syntax 3, therefore I think removing "(after the @charset rule, if any)" would avoid any confusion about @layer statement preceding @charset (valid, if I am not mistaken).

@cdoublev
Copy link
Collaborator Author

cdoublev commented Apr 3, 2023

Requirements are quite fragmented and seem to lack specifics on their motivations, which makes them even more difficult to grasp, but after re-reading, there do not seem to me to be any contradictions (at least in CSS Cascade 5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants