[csswg-drafts] [css-namespaces-3] Clarify the validity of @namespace preceding @import (#7001)

cdoublev has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-namespaces-3] Clarify the validity of @namespace preceding @import ==
> Any `@namespace` rules must follow all `@charset` and `@import` rules and precede all other non-ignored at-rules and style rules in a style sheet. [...]
>
> A syntactically invalid `@namespace` rule (whether malformed or misplaced) must be ignored.

https://drafts.csswg.org/css-namespaces-3/#syntax

In the following case, both Chrome/Firefox do not ignore `@namespace` but ignore the `@import`:

```html
<style>
  @namespace test "http://www.w3.org/2000/svg";
  @import "./stylesheet.css"; /* Declares `div { color: green }` */
  test|svg {
    background-color: red;
  }
</style>
<div>Green?</div>
<svg width="500" height="500"></svg>
```

A strict interpretation would be that `@namespace` is misplaced and should be ignored. Maybe its context rules should be defined similarly as for [`@import`](https://drafts.csswg.org/css-cascade/#at-import):

> Any `@namespace` rules must precede all other valid style rules and at-rules that are not `@import` in a style sheet (ignoring `@charset`), or else the `@namespace` rule is invalid.

Also, I did not test the current UA behavior with `@namespace` preceding `@charset`, but I understood that all other rules following the first `@charset` rules are ignored, therefore it could be allowed.

> User agents must ignore any `@charset` rule not at the beginning of the style sheet. When user agents detect the character encoding using the BOM and/or the @charset rule, they should follow the following rules:
>
> Except as specified in these rules, all @charset rules are ignored.

https://drafts.csswg.org/css2/#charset%E2%91%A0

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7001 using your GitHub account


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

Received on Monday, 31 January 2022 11:00:48 UTC