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

@annevk commented on this pull request.

This looks good to me. I'm not particularly happy about the current hooks as they don't deal with ordering very well. I suppose HTML largely takes care of that, but at some point we should have something better.

> + <p>While the <a>insertion steps</a> cannot execute JavaScript (among other things), it is expected
+ that they will indeed have script-observable consequences. Consider the below example:

s/it is expected that//

> + const h1 = document.querySelector('h1');
+
+ const fragment = new DocumentFragment();
+ const script = fragment.appendChild(document.createElement('script'));
+ const style = fragment.appendChild(document.createElement('style'));
+
+ script.innerText= 'console.log(getComputedStyle(h1).color)'; // Prints 'rgb(255, 0, 0)'
+ style.innerText = 'h1 {color: rgb(255, 0, 0);}';
+
+ document.body.append(fragment);
+ </code></pre>
+
+ <p>The script in the above example prints <code class=lang-javascript>'rgb(255, 0, 0)'</code>
+ because the following happen in order:
+
+  <ol>

Indentation here seems wrong. Should be indented one, no?

> @@ -2752,6 +2812,16 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
  <var>parent</var> with <var>nodes</var>, « », <var>previousSibling</var>, and <var>child</var>.
 
  <li><p>Run the <a>children changed steps</a> for <var>parent</var>.
+
+ <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>, run the <a>post-insertion steps</a> with
+   <var>inclusiveDescendant</var>.
+  </ol>
+ </li>

(I've also never quite managed to wrap my head around script runners.)

>  <!-- See https://github.com/whatwg/dom/issues/34#issuecomment-125571750 for why we might need to
      adjust this further based on the requirements of the script element. There might be other ways
      to define that though as Olli suggests, so leaving that out for now. -->
 
+<p><a lt="Other applicable specifications">Specifications</a> may also define <dfn export
+id=concept-node-post-insert-ext>post-insertion steps</dfn> for all or some <a for=/>nodes</a>. The
+algorithm is passed <var ignore>insertedNode</var>, as indicated in the <a
+for=/>insert</a> algorithm below.
+
+<p class=note>The purpose of the <a>post-insertion steps</a> is to provide an opportunity for <a
+for=/>nodes</a> to perform any insertion-related operations that modify the <a>node tree</a> that
+<var ignore>insertedNode</var> <a>participates</a> in, create <a for=/>browsing contexts</a>, or
+otherwise execute JavaScript. These steps allow a batch of <a>nodes</a> to be <a for=/>inserted</a>
+<i>atomically</i> with respect to script, with all major side effects occurring <i>after</i> the
+batch insertions into the <a>node tree</a> is complete, but before <a lt="notify mutation
+observers"><code>MutationObserver</code>s are notified</a>. This ensures that all pending <a>node

I tend to agree with Olli. It's confusing as there are other things you could use to observe the mutation even earlier. You could maybe say "before script has had a chance to observe the mutation" but even that is a stretch (today) given mutation events.

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

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

Received on Tuesday, 2 April 2024 16:40:54 UTC