Closed Bug 1596458 Opened 5 years ago Closed 5 years ago

Incorrect innerHTML behavior for ShadowRoot

Categories

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

defect

Tracking

()

RESOLVED FIXED
mozilla72
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?

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

Pushed by bzbarsky@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/29897d3c1b7f
part 1.  Fix CreateContextualFragment in XML to not accidentally trigger custom element constructors.  r=hsivonen
https://hg.mozilla.org/integration/autoland/rev/4460bd1e6ccb
part 2.  Fix the innerHTML setter for shadow DOM cases in XML to supply the right context.  r=emilio
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/20343 for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Status: NEW → RESOLVED
Closed: 5 years 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.

Attachment

General

Created:
Updated:
Size: