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

@annevk I can be mindful but editing doesn't trigger emails notifications so in this 5+ years discussion I wanted to be sure all the thoughts are well understood ... but I've said everything needed to say, except I am answering your question too in here.

> imperative creation and insertion

fair enough, but nothing new neither. the `attributeChangedCallback` fires *before* `connectedCallback` in non-imperative ways component are already part of the DOM, but can actually fire after if an imperative declaration already landed on the live document or not. This means there's no guarantee of callbacks order already in the current specification that has, indeed, 3 ways to consider custom elements, but it doesn't invalidate the `parsedCallback` idea:

  * if imperative, that can trigger right after the constructor, no issues caused to the logic ... it's still the place to add a MutationObserver if needed/meant or the place `this.children.length` can be checked
  * in every other cases, it's inevitably *after* `connectedcallback` because a `parsedCallback` cannot possibly happen before a `connectedCallback` as the parser is top-down

So yes, the imperative case triggers `parsedCallback`, if present, before `attributeChanged` or `connected`, because that's imperative, which is also the least known/used case out there, but the `parsedcallback` primitive would ensure the state of the component is well understood (even if imperative) while right now we need ugly dances around.

**If** the idea is instead an `Element.prototype.whenParsed()` solution, none of this concerns matters, as the promise will resolve a tick later, so that attributes changed, or connected callbacks, would eventually already be fired in the between.



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

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

Received on Friday, 10 March 2023 14:14:18 UTC