Skip to content

Timing of CE reactions with adoption agency #13072

Open

Description

@noamr

When the adoption agency algorithm
(AAA) moves already-constructed nodes around, the spec never pushes an element queue, so any custom element reactions caused by those moves end up in the backup element queue and only run at the next microtask checkpoint. Chromium (per the code pointers in #12758 (comment)
) appears to instead wrap each individual construction-site move in a CEReactionsScope, so the reactions run synchronously after each move. This is not interoperable and not covered by WPT. Which behavior do we want?

e.g.:

<script>
customElements.define("my-element", class extends HTMLElement {
  connectedCallback() { log.push("connected " + this.isConnected); }
  disconnectedCallback() { log.push("disconnected " + this.isConnected); }
});
const log = [];
</script>
<b><p><my-element></my-element></b><script>console.log(log);</script>

Options

  1. Status quo: reactions for AAA moves go to the backup element queue. Simple, but the callbacks run after arbitrary later content has been parsed (possibly after a subsequent inline <script> has run and observed the DOM), and disconnectedCallback can run while the element is already connected again.
  2. One element queue per move (what Chromium seems to do): wrap each remove/insert/append in the AAA in its own element queue. Every callback then sees an accurate isConnected, and the callback ordering is per move. This is also closest to what insert an element at the adjusted insertion location already does.
  3. One element queue around the whole AAA run: same set of callbacks as (2), but batched and run once at the end of the AAA. Fewer re-entrancy points, but disconnectedCallback still runs while the element is connected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions