Created attachment 346427 [details] A page with custom elements that log when their constructor and connectedCallback are called. When a group of custom elements are created through the parser (either because they are in the main document's HTML or are in a string being set to a connected element's `innerHTML` property), they are all constructed before any have their `connectedCallback` called. For example, for this tree: <c-e id="A"> <c-e id="B"></c-e> </c-e> <c-e id="C"></c-e> Safari calls the constructor and connectedCallback of each in this order: - constructor A - constructor B - constructor C - connectedCallback A - connectedCallback B - connectedCallback C However, the order should be this: - constructor A - connectedCallback A - constructor B - connectedCallback B - constructor C - connectedCallback C Relevant spec text: https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token The 'in-document HTML' case would have 'will execute script' set to true, meaning that the interleaved order above is the expected order, AFAICT. I think Safari's `innerHTML` is correct here though: it would have 'will execute script' set to false, so the connectedCallback reactions would all be delayed until they're popped at the end.
Chrome and Firefox seem to have the opposite problem; their `innerHTML` setters act as if the elements being created were in the main document: https://bugs.chromium.org/p/chromium/issues/detail?id=870512 https://bugzilla.mozilla.org/show_bug.cgi?id=1480632
Do we have any WPT tests that cover these cases?
For the synchronous case ('in-document HTML'), the patch on bug 188190 is supposed to force execution of the connectedCallBack immediately after insertion of the element (There is WPT test to ensure the element is indeed empty when connectedCallBack is called). That might improve things, but I don't know beforehand what we do regarding the order of constructor call / element insertion, especially since HTMLConstructionSite uses an m_taskQueue to delay insertion.
(BTW, the other two bugs I mentioned are now closed: my interpretation of the spec was wrong.)
<rdar://problem/42987289>
(In reply to Russell Bicknell from comment #4) > (BTW, the other two bugs I mentioned are now closed: my interpretation of > the spec was wrong.) Thanks for the update. For the non-synchronous case (innerHTML) note that bug 188327 was recently fixed.
Okay, this is caused by the bug 188189 so I'll fix it there. *** This bug has been marked as a duplicate of bug 188189 ***