[csswg-drafts] [cssom] Overlapping step 5 and 6 in insert a CSS rule (#8654)

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

== [cssom] Overlapping step 5 and 6 in insert a CSS rule ==
I think step 6 of [*insert a CSS rule*](https://drafts.csswg.org/cssom-1/#insert-a-css-rule) can never throw...

  > 5. If `new rule` cannot be inserted into list at the zero-index position index due to constraints specified by CSS, then throw a `HierarchyRequestError` exception.
  > 6. If `new rule` is an `@namespace` at-rule, and list contains anything other than `@import` at-rules, and `@namespace` at-rules, throw an `InvalidStateError` exception.

... because [CSS Namespaces 3](https://drafts.csswg.org/css-namespaces-3/#syntax) defines this constrainst (detected in step 5):

  > 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.

However CSS Namespaces 3 does not explicitly define whether a non-conforming `@namespace` must be invalid or if it must be ignored.

```html
<style>
  style {}
  @namespace ns "http://ns.org";
</style>
<script>
  try {
    document.styleSheets[0].insertRule('@namespace ns "http://ns.org";', 1)
  } catch (error) {
    // Chome: InvalidStateError
    //    FF: HierarchyRequestError
    console.log(error.name) 
  }
</script>
```

If it must be invalid and I am not mistaken, switching step 5 and 6 could be an alternative to removing step 6.

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


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

Received on Tuesday, 28 March 2023 14:24:15 UTC