Re: [whatwg/dom] Introduce DOM post-insertion steps (PR #1261)

@domfarolino commented on this pull request.



> +  modify the tree's structure, making live traversal unsafe, possibly leading to the
+  <a>post-insertion steps</a> being called multiple times on the same <a>node</a>.</p>
+ </li>
+
+ <li>
+  <p>For each <var>node</var> in <var>nodes</var>, in <a>tree order</a>:
+
+  <ol>
+   <li><p>For each <a>shadow-including inclusive descendant</a> <var>inclusiveDescendant</var> of
+   <var>node</var>, in <a>shadow-including tree order</a>, <a for=list>append</a>
+   <var>inclusiveDescendant</var> to <var>staticNodeList</var>.
+  </ol>
+ </li>
+
+ <li><p><a for=list>For each</a> <var>node</var> in <var>staticNodeList</var>, if <var>node</var> is
+ <a>connected</a>, then run the <a>post-insertion steps</a> with <var>node</var>.

The idea is that post-insertion steps should not run on elements that aren't connected to the DOM. For those elements, we shouldn't be performing actions that modify the frame tree or load resources or anything else the post-insertion steps are responsible for outside of the insertion steps.

We could do this implicitly / vaguely which is kind of how HTML does it now, by specifying something like ["becomes connected"](https://html.spec.whatwg.org/multipage/infrastructure.html#becomes-connected) steps (but for post-insertion steps), which supposedly run "during" the "insertion steps" (without any ordering specified) with a "is connected" precondition built in. Or we could do it slightly more explicitly by not having an "is connected" gate specified in DOM, and relying on each element's post-insertion steps to have a precondition that early-returns without a DOM connection. That doesn't seem better though. So I think the condition in this PR is the most straightforward way of achieving this. We have tests too that ensure e.g., scripts don't run when disconnected after insertion (by other post-insertion steps, in the trickiest of cases, for example).

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/1261#discussion_r1590317543
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/pull/1261/review/2039697374@github.com>

Received on Sunday, 5 May 2024 13:43:39 UTC