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

@domfarolino commented on this pull request.



> @@ -2652,6 +2652,50 @@ 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 either <var>parent</var> or <var>node</var> are not <a>connected</a>, then
+ <a>throw</a> a "{{HierarchyRequestError!!exception}}" {{DOMException}}.</p></li>

> Disconnected -> connected could theoretically also been seen as stated preserving since the disconnected node didn't have any previous state so there is nothing to preserve.

I think I disagree. The state could be null `contentDocument`, lack of focus, no form owner, and more etc. That "no state" is still a kind of state, and it'd either be:
 - **Changed** by becoming connected into a document, and running the many hooks that the platform does during that milestone — some of which initialize iframe setup, run script, etc. In this case, move just becomes insertion, which we don't want to do because the two are distinct primitives.
 - **Not changed**, by just inserting the element into the DOM and leaving it kind of dead/void. This would be completely new and I think kind of weird. For example `parent.moveBefore(disconnectedIframe, null)` would make `disconnectedIframe` finally connected, but with a null content document because we never initialized the setup. In that case, it feels like there was no reason to *move* it into the DOM in the first place. Same goes for other things with form owners, executable `<script>`s, etc. I'm not sold that this is a real use case.

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

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

Received on Wednesday, 20 November 2024 22:03:44 UTC