Skip to content

[css-cascade] Clarify when an @import rule is valid #5313

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
andreubotella opened this issue Jul 11, 2020 · 2 comments · Fixed by #5358
Closed

[css-cascade] Clarify when an @import rule is valid #5313

andreubotella opened this issue Jul 11, 2020 · 2 comments · Fixed by #5358

Comments

@andreubotella
Copy link
Member

The definition of when an @import rule is valid is:

Any @import rules must precede all other at-rules and style rules in a style sheet (besides @charset, which must be the first thing in the style sheet if it exists), or else the @import rule is invalid.

Given that in CSS3 @charset is no longer a rule, it's not clear what the interpretation of that sentence would be when the parser finds an invalid rule named @charset that hasn't been interpreted as a fallback encoding marker by the input byte stream.

I've run a few tests, and the behavior of Firefox, Chrome and Epiphany / GNOME Web (a Webkit representative, since I don't have access to Mac or iOS machines) match: an @import rule is valid if every rule before it in the stylesheet is either invalid or an @import rule.

And this behavior is in fact consistent with this text in css-syntax:

If any style rule is invalid, or any at-rule is not recognized or is invalid according to its grammar or context, it’s a parse error. Discard that rule.

But in any case, the language in css-cascade should probably be updated to not refer to @charset as a rule and to clarify this, even if the correct behavior can be reasoned out from other specs.

@fantasai
Copy link
Collaborator

That should probably say "all other valid", since invalid stuff should not affect the interpretation of the stylesheet.

andreubotella pushed a commit to andreubotella/csswg-drafts that referenced this issue Jul 24, 2020
This change also modifies the mention of @charset as an example of an
at-rule with restrictions on its relative ordering to replace it with
@namespace, since @charset is no longer a valid rule.

Closes w3c#5313.
@fantasai
Copy link
Collaborator

Spec updated and republished.

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

Successfully merging a pull request may close this issue.

2 participants