Re: [whatwg/dom] shadowRoot.innerHTML parsing elements from another realm/iframe (#977)

I don't think there is any ambiguity here. We need to start from the [`innerHTML`](https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin)'s setter, which creates a new Document to parse the specified HTML in the [HTML fragment parsing algorithm](https://html.spec.whatwg.org/#html-fragment-parsing-algorithm). Because it is a new document, the step to create a new element in it will not result in a synchronous custom element construction, nor does it get immediately upgraded to a custom element upon return from the fragment parsing algorithm.

`innerHTML` then [replaces all](https://dom.spec.whatwg.org/#concept-node-replace-all) with the newly created fragment within the context object, the [`ShadowRoot`](https://dom.spec.whatwg.org/#shadowroot). Replacing all with the fragment will [insert](https://dom.spec.whatwg.org/#concept-node-insert) the fragment, which will [try to update](https://html.spec.whatwg.org/multipage/custom-elements.html#concept-try-upgrade) every candidate element in the inserted subtree.

The first thing that happens with [trying to update](https://html.spec.whatwg.org/multipage/custom-elements.html#concept-try-upgrade) an element is [looking up a custom element definition](https://html.spec.whatwg.org/multipage/custom-elements.html#look-up-a-custom-element-definition) given the element's [node document](https://dom.spec.whatwg.org/#concept-node-document). But by this point, we had already [adopted](https://dom.spec.whatwg.org/#concept-node-adopt) this node into ShadowRoot's node document in step 7.1. of [inserting](https://dom.spec.whatwg.org/#concept-node-insert) the fragment. The node document of `ShadowRoot` in turn is the main document at this point since `document.body.appendChild(elmFromAnotherDoc)` had [adopted](https://dom.spec.whatwg.org/#concept-node-adopt) to it.

Because we're [looking up a custom element definition](https://html.spec.whatwg.org/multipage/custom-elements.html#look-up-a-custom-element-definition) with the element's node document, which is the main document, we would find and only find custom elements defined in the main document.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/977#issuecomment-831627342

Received on Tuesday, 4 May 2021 01:00:50 UTC