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

I was referring to these checks 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)
  ;
}
```

which is starting to become very ugly and a performance hazard due all those checks needed per every single node that would like to be moved ... I don't think a `try/catch` would perform worse than that ... and still it'd be slower.

If the method needs to do all those checks internally, even a companion method to know if a node can be moved would be duplication of checks and intents ... the fastest best way to have all at once seems to be the third argument then, with a dev-defined callback.

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

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

Received on Monday, 25 November 2024 11:19:05 UTC