I believe that CSSStyleSheet.replace() and CSSStyleSheet.replaceSync() are missing a step to parse the input rules according to the appropriate CSS specifications, similarly as in parse a CSS rule, run by insert a CSS rule, run by CSSStyleSheet.insertRule(). Currently, it only parses against basic syntax rules with parse a list of rules, which would mean that something like @namespace "ns" { color: red } should be added to the CSS rules, which is something that UAs are not doing, obviously.
- Let
rules be the result of running parse a list of rules from text. If rules is not a list of rules (i.e. an error occurred during parsing), set rules to an empty list.
- If rules contains one or more
@import rules, remove those rules from rules.
- Set sheet’s CSS rules to
rules.
https://drafts.csswg.org/cssom/#dom-cssstylesheet-replace
https://drafts.csswg.org/cssom/#synchronously-replace-the-rules-of-a-cssstylesheet