- From: James Browning <notifications@github.com>
- Date: Sun, 31 Jul 2022 01:29:16 -0700
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/946/1200377464@github.com>
> One can also look at it this way: templates are supposed to be inert, and fast. That is why frameworks in benchmarks use `cloneNode` as the most speedy way to create element instances. > > I don't know what the adoption process is, but elements gotten from cloneNode and inserted into the main document **_will_** be upgraded at that point. The confusing point isn't that elements don't get upgraded on `cloneNode`, the confusing point is that calling `customElements.upgrade` on such elements doesn't do anything because they aren't associated to the main document. I doubt most authors even know that there is a second document that templates associate their nodes to. The spec says the [motiviation for this is](https://html.spec.whatwg.org/multipage/scripting.html#appropriate-template-contents-owner-document): > Each [Document](https://html.spec.whatwg.org/multipage/dom.html#document) not created by this algorithm thus gets a single [Document](https://html.spec.whatwg.org/multipage/dom.html#document) to act as its proxy for owning the [template contents](https://html.spec.whatwg.org/multipage/scripting.html#template-contents) of all its [template](https://html.spec.whatwg.org/multipage/scripting.html#the-template-element) elements, so that they aren't in a [browsing context](https://html.spec.whatwg.org/multipage/browsers.html#browsing-context) and thus remain inert (e.g. scripts do not run). Meanwhile, [template](https://html.spec.whatwg.org/multipage/scripting.html#the-template-element) elements inside [Document](https://html.spec.whatwg.org/multipage/dom.html#document) objects that are created by this algorithm just reuse the same [Document](https://html.spec.whatwg.org/multipage/dom.html#document) owner for their contents. I don't see why such a concept need exist. Like scripts not connected to a document (e.g. created by `.createElement`) don't evaluate even though their `.ownerDocument` is `document`. The trigger for script evaluation is connectedness, which template nodes never are anyway as they're part of a document fragment which isn't connected to the main document. Even setting the template weirdness aside, the fact is the whole point of `customElements.upgrade` is that it can upgrade elements *without* connecting them. The fact that it can't upgrade elements from a template document is pretty arbitrary given that it's entirely possible to adopt into the main document, upgrade, then return the elements to the previous document. -- Reply to this email directly or view it on GitHub: https://github.com/WICG/webcomponents/issues/946#issuecomment-1200377464 You are receiving this because you are subscribed to this thread. Message ID: <WICG/webcomponents/issues/946/1200377464@github.com>
Received on Sunday, 31 July 2022 08:29:28 UTC