Consider the following scenario. I have element foo
which has a child element, bar
. Now foo
will make use of bar
in someway, this could be calling a method from bar
's prototype or just checking the instance. Due to the nature of a DOM tree structure foo
gets lifecycle events first createdCallback
and attachedCallback
. If you try and reference any child custom elements within those callbacks, they have not be initialised correctly and their prototype is HTMLElement
and not of their respected prototypes defined when registering the element. This means that the assertions in foo.js
will fail sadly.
In order to use the instance of the element with it's correct prototype, you must allow all lifecycle events for each custom element, including their children, to complete before using the instances of those custom elements.