Open emilio opened 6 years ago
So, one problematic issue is:
"A type selector or universal selector containing a namespace prefix that has not been previously declared is an invalid selector."
which means the whole rule will be dropped at parse-time. Reviving that rule if a @namespace rule is inserted does not sound feasible in Blink, nor makes sense spec-wise. Also, what should happen if you remove a @namespace rule? Should the style rules using that prefix be removed?
I think it makes sense to not allow @namespace rule mutations.
So that complexity is already worked around in the spec in:
https://drafts.csswg.org/cssom/#insert-a-css-rule
Where step 6 says:
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.
But given we're bogus even with that rule accounted for, and that that restriction is already pretty limiting, I think it makes sense to just disallow it completely.
How do you construct a stylesheet with a namespace rule in it, then?
cssText or such I guess. You can then append other style rules at your will.
Stylesheets don't have a .cssText
tho. ^_^
Whoops, never write from memory. textContent
and similar on a <style>
element works and creates a new sheet, but yeah, agree it's uglier...
I was fixing an edge case in Firefox's CSSOM implementation (https://bugzilla.mozilla.org/show_bug.cgi?id=1464865) when I started realizing of all the different bugs that our implementation had.
Well, turns out most of the other implementations also have them, for example, even this simple test-case:
Is wrong and shows green in every single browser. I don't even want to start thinking of preserving the order when the namespace string is the same and such. Nobody removes from the map either from my testing.
The reason this happens is because everyone to the best of my knowledge represents namespaces as a single hash map, and dealing with changes to it is slightly painful.
These bugs can of course be fixed, but I'm not aware of anyone trying to improve the situation here, and personally having the namespace map immutable at parse time would be really nice.
Is there anyone planning to fix implementations here? Or would it be reasonable to consider trying to drop deletion / insertion of namespace rules via the OM?
cc @lilles @FremyCompany @zcorpan