Closed Bug 1596458 Opened 11 months ago Closed 10 months ago

Incorrect innerHTML behavior for ShadowRoot


(Core :: DOM: Core & HTML, defect, P2)




Tracking Status
firefox72 --- fixed


(Reporter: bzbarsky, Assigned: bzbarsky)




(2 files)

Per spec at 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?

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.

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

Priority: -- → P2
Pushed by
part 1.  Fix CreateContextualFragment in XML to not accidentally trigger custom element constructors.  r=hsivonen
part 2.  Fix the innerHTML setter for shadow DOM cases in XML to supply the right context.  r=emilio
Created web-platform-tests PR for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla72
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.