Incorrect innerHTML behavior for ShadowRoot
Categories
(Core :: DOM: Core & HTML, defect, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox72 | --- | fixed |
People
(Reporter: bzbarsky, Assigned: bzbarsky)
References
Details
Attachments
(2 files)
Per spec at https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml step 1 the context element for setting innerHTML on a ShadowRoot should be the shadow host. We don't do that, which means that, for example, in an XHTML document setting innerHTML on a ShadowRoot creates elements in the null namespace by default, not the default namespace of the shadow host.
I tried to figure out a problem here in non-XHTML HTML, but the set of tags that are allowed to have shadow roots is pretty limited and mostly doesn't have interesting parsing (e.g. no shadow roots on a <tr>
). The only one in there that looks interesting is <p>
, and even there setting its innerHTML
to something like "<p>foo</p>"
leads to nested <p>
in the normal (no shadow DOM) case. So I think in practice this is only observable in XHTML?
Comment 1•5 years ago
|
||
Comment 2•5 years ago
|
||
It seems we only do that for HTML (not XHTML) documents though: https://searchfox.org/mozilla-central/rev/e7c61f4a68b974d5fecd216dc7407b631a24eb8f/dom/base/FragmentOrElement.cpp#2035
Assignee | ||
Comment 3•5 years ago
|
||
Ah, yes. For XML the proper context consists of a lot more than just a localname and namespace id... And we're not using that in XHTML anyway, as you note.
Assignee | ||
Comment 4•5 years ago
|
||
OK, I tried writing a fix for this and a test to go with it, but the result fails the test, because the context now includes the custom element, and setting innerHTML in XML prepends open-tag bits for all the ancestors to the string, so the innerHTML setter in my custom element constructor ends up triggering custom element bits the custom element tag name in the context (!), which is all sorts of bogus.
Thinking about how to fix that now...
Assignee | ||
Comment 5•5 years ago
|
||
Assignee | ||
Comment 6•5 years ago
|
||
Updated•5 years ago
|
Comment 10•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/29897d3c1b7f
https://hg.mozilla.org/mozilla-central/rev/4460bd1e6ccb
Description
•