-
Notifications
You must be signed in to change notification settings - Fork 658
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
[cssom] Overlapping step 5 and 6 in insert a CSS rule #8654
Comments
I am sorry, const sheet = new CSSStyleSheet()
sheet.insertRule('style {}')
sheet.insertRule('@namespace ns "http://ns.org";') // InvalidStateError I guess I miss an hour of sleep... |
Right, step 6 isn't detecting positional errors, it's detecting a "potentially changes the interpretation of all other rules" action and disallowing it. There's nothing wrong with the stylesheet that Step 6 throws on in theory, but in practice it means a change to the entire sheet datastructure, so it's not a localized change. |
Would you be kind enough to also explain me how the interpretation of a single |
They don't. But carefully dividing CSS syntax into "things that get affected by a namespace change" and "things that don't", and then requiring engines to verify that the stylesheet contains only the "not affected" rules, and keeping that division up-to-date as we add new rules, is all in all not a worthwhile use of anyone's time. The simple rule as it exists does the job sufficiently well. |
Ok, thanks. I have no problem with this position but I needed it clarified. |
Actually I do not see how it makes it less complex for engines. An author could write this style sheet: @layer base;
@namespace ns "https://ns.org"; But it could not construct the corresponding style sheet? const sheet = new CSSStyleSheet()
sheet.insertRule('@layer base;')
sheet.insertRule('@namespace ns "https://ns.org";', 1) // InvalidStateError It seems to boil down to sharing the same validation function... function isInvalidStateForNamespace(rule, rules) {
return rules.some(isNotImportOrNamespaceOrLayerStatement)
}
function parseStyleSheet(rules) {
const valid = []
for (const rule of rules) {
if (isNamespace(rule) && isInvalidStateForNamespace(rule, valid)) {
continue
}
// ...
valid.push(rule)
}
return rules
}
function insertCSSRule(rule, list) {
// ...
// Nope, CSSOM requires a different validation here!
if (isNamespace(rule) && isInvalidStateForNamespace(rule, list)) {
throw InvalidStateError
}
// ...
} |
Correct: they could write such a sheet, and they could not construct such a sheet. Again, this is because making and keeping the OM rule "correct" simply isn't worth anyone's time. To a first approximation, no one constructs and inserts |
I think step 6 of insert a CSS rule can never throw...
... because CSS Namespaces 3 defines this constrainst (detected in step 5):
However CSS Namespaces 3 does not explicitly define whether a non-conforming
@namespace
must be invalid or if it must be ignored.If it must be invalid and I am not mistaken, switching step 5 and 6 could be an alternative to removing step 6.
The text was updated successfully, but these errors were encountered: