Re: [whatwg/dom] Introduce `moveBefore()` state-preserving atomic move API (PR #1307)

@domfarolino commented on this pull request.



> @@ -2652,6 +2652,63 @@ of a <var>node</var> into a <var>parent</var> before a <var>child</var>, run the
  <!-- Technically this is post-insert. -->
 </ol>
 
+<p>To <dfn export for=Node id=concept-node-ensure-pre-move-validity>ensure pre-move validity</dfn>
+of a <var>node</var> into a <var>parent</var> before a <var>child</var>, run these steps:
+
+<ol>
+ <li>
+  <p>If any of the following conditions are true</p>
+
+  <ul>
+   <li><p><var>parent</var> is <a>connected</a> and <var>node</var> is not <a>connected</a>; or</p></li>
+
+   <li><p><var>parent</var> is not <a>connected</a> and <var>node</var> is <a>connected</a>,</p></li>
+  </ul>

So, I think back when we only supported the connected->connected case, the "shadow-including root matches" check was right, because "shadow-including root" was essentially the same as "node document", in the connected case.

But now that we support the disconnected->disconnected case, I actually think the "shadow-including root" check is too strict, right? For example, imagine:

```js
const divA = document.createElement('div');
const p = divA.appendChild(document.createElement('p'));
const divB = document.createElement('div');

// Throws because divB's shadow-including root does not match p's, since they're both disconnected.
divB.moveBefore(p, null);
```

That is, in the disconnected->disconnected case, it is way more likely that the target node and destination container's shadow-including roots will not match, since in the disconnected case, a shadow-including root just tops-out at the nearest disconnected parent. So my proposal is to simply change the shadow-including root comparison to instead compare node documents. I'll do that now, and please let me know if you think that sounds good.

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

Message ID: <whatwg/dom/pull/1307/review/2490262077@github.com>

Received on Monday, 9 December 2024 22:33:28 UTC