Re: [WICG/webcomponents] Need a callback for when children changed or parser finished parsing children (#809)

I think there's multiple valid implementations of hydrating a component. One might be as @annevk suggests which allows individual elements inside a component to hydrate or be loaded independently.

However I think it's equally valid to consider an entire component as a "hydration unit" in which hydration happens for the whole thing at once. Take for example a simple counter (button and label which gets incremented each click). You could implement this via @annevk's approach and watch for DOM mutations, however this is 1) excessively complicated IMHO and 2) kinda pointless. It's completely unnecessary complexity given that neither the button nor the label are useful to hydrate independently. Taking the effort to observe them individually still requires waiting on both to be loaded anyways. Not only that, but a child could be half-parsed. A `MutationObserver` could trigger a callback part way through parsing the label for example and hydration might start prematurely, before it's full text is loaded (happy to include a more concrete example here, but on mobile ATM).

While some very large components might benefit from making individual elements independently hydratable, I think it is a very useful and common pattern for developer to treat the whole component as a hydration unit, and it is difficult to support that model without a parser-integrated hook to know when all it's input HTML has been fully applied to the DOM.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/809#issuecomment-1460319527
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/809/1460319527@github.com>

Received on Wednesday, 8 March 2023 15:19:11 UTC