Netflix / x-element

A dead simple starting point for custom elements.
Apache License 2.0
28 stars 12 forks source link

Setup listeners before initial render. #126

Closed theengineear closed 1 year ago

theengineear commented 1 year ago

Previously, “initializeHost” was called ahead of “addListeners”. There was an edge case where such depth-first initialization made it possible for synchronous events from children to be emitted before the delegated event listeners had been setup on the parent.

This change ensures the following happens in order on first connection:

  1. The host itself is initialized.
  2. The static listeners are added.
  3. The host undergoes its initial render.

Previously, (2) and (3) were conceptually swapped.

theengineear commented 1 year ago

@klebba — Want to give this a review? It's slightly more nuanced than I had previously thought. But, I think this is the correct factoring.