Re: [whatwg/dom] Declarative Shadow DOM (#831)

> the "overhead" of creating the template document and moving contents around

After discussion with @smaug---- on this topic, this seems to be the main concern.

> It does seem to do somewhat redundant work by creating template and then later removing it and creating nodes in another document and then adopting them to another document almost immediately.

I tend to agree that this is a bit odd, and it's also odd that this behavior is potentially observable by user script (e.g. a `<script>` inside of the `<template>`, which [can mutate the template during parsing](https://codepen.io/nolanlawson-the-selector/pen/NWMjZKd) (bug?), or `MutationObserver`, although that seems [fixed now](https://bugs.chromium.org/p/chromium/issues/detail?id=1315283)).

[This point about streaming](https://github.com/mfreed7/declarative-shadow-dom/blob/a52e70f560e30c8aac2543396b1706e21445c2db/README.md#timing-attach-the-shadow-on-opening-or-closing-template-tag) is also very compelling to me:

> When the shadow root is attached only on the **closing** `</template>` tag, nothing will be rendered until that point. If the page consists of a large, nested set of web components, then nothing will be rendered until the parser encounters the final closing tag of the outermost component. This problem isn’t as bad if the page is built as a light dom document containing many small web-components-based widgets.

Unfortunately in the case of the Salesforce CRM app, this last assumption is not correct – essentially the entire page is enclosed in a shadow root. So we would not get the benefits of streaming in the current approach (AIUI).

Based on both the perf issue and the user-observability issue, I would side with @smaug---- in favor of making the `<template>` purely syntactic and attaching it upon opening, rather than creating an explicit `<template>` and attaching it upon closing.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/831#issuecomment-1251370607

You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/831/1251370607@github.com>

Received on Monday, 19 September 2022 18:10:26 UTC