Re: [whatwg/dom] Proposal: a DocumentFragment whose nodes do not get removed once inserted (#736)

rniwa left a comment (whatwg/dom#736)

> [@rniwa](https://github.com/rniwa)
> 
> > But the devil is in the details. Suppose we had an element e_1 and NodeGroup (the new node type) was inserted under e_1. Then e_1.childNodes[0] will return the NodeGroup but what happens to e_1.children[0]. Would it return the first element child under NodeGroup? Or would it return undefined because there is no direct child of e_1 which is an element. What happens if NodeGroup had another NodeGroup as a direct child. Would we be "unwrapping" nested NodeGroups until we hit a real non-NodeGroup Node? In that case, this proposal is very much similar to DOM Part proposal we made. The only difference is whether NodeGroup appears as an actual Node or not.
> 
> No it's not that complex, `NodeGroup`, is a `ChildNode` like any other `ChildNode`, they can be nested, within each-other. `NodeGroups` appear in the `childNodes` like any other `ChildNode`. It's literally a `ChildNode & ParentNode`, acts exactly as you expected, you can discover them while tree-walking like any other node. Only difference is, it's transparent to query selectors, that's all.

Then that's the second model I had described where all intermediary `NodeGroup` nodes appear in DOM as regular nodes.

> Also this `<group>` idea made me think.
> 
> When it comes to something like `<group>`, I believe, it has nothing to do with HTML or HTML parsing? It's about querying the DOM. Instead of introducing a new tag, we could have an attribute similar to `inert` that makes query selectors skip the element, effectively making it transparent.

That doesn't work in the case you want to repeat `td` inside `tr` for example because HTML parser won't let you introduce a div like element between those two.

> This new attribute would simply:
> 
> * Act exactly like an `<div>` with `display: contents`, no difference, inheriting all its existing gotchas as well.
> * And It would be transparent to query selectors in both JS and CSS.

I don't think that simple design works because of HTML parser constraints. In order to support manipulation of DOM tree anywhere, this new thing has to behave like `template` element (i.e. it can appear anywhere).

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

Message ID: <whatwg/dom/issues/736/2757224752@github.com>

Received on Thursday, 27 March 2025 08:52:40 UTC