Re: [whatwg/dom] Atomic move operation for element reparenting & reordering (Issue #1255)

> I was referring to these checks [#1307 (comment)](https://github.com/whatwg/dom/pull/1307#issuecomment-2491906616) but now there is a new one needed for comments ... comments nodes are used in both _lit-html_ and my libaries, among others, to pin-point fragments and when these fragments are moved their comment nodes move along without needing to leave the living dom, they are just an indirection ... so it's new to me that comments can't be moved (and why? these are the least problematic thing ever when it comes to repaint/reflow) and that mentioned check should become:
> 
> ```js
> const moveOrInsertNode = (container, node, ref_node = null) => {
>   const canMove = (
>     container.isConnected &&
>     node.isConnected &&
>     node.nodeType !== node.COMMENT_NODE &&
>     (!ref_node || ref_node.parentNode === container)
>   );
>   return canMove ?
>     container.moveBefore(node, ref_node) :
>     container.insertBefore(node, ref_node)
>   ;
> }
> ```

Sorry, the restriction about comments is for the parent. You can move comment nodes.
`(!ref_node || ref_node.parentNode === container)` is not related to move, it would also throw for `insertBefore`.
So you'll be left with `canMove = container.isConnected === node.isConnected`

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1255#issuecomment-2497745040
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1255/2497745040@github.com>

Received on Monday, 25 November 2024 11:26:17 UTC