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

WebReflection left a comment (whatwg/dom#736)

dunno if it'd be too late but a way to think about *range-comment* to me would be, implementation wise:

  * add a `document.createDocumentRange()` (name TBD if too similar to current `Range`) that:
    * behaves exactly like a document fragment, but ...
    * once live/appended has a start-comment and and end-comment around its nodes and those nodes cannot be reached or replaced via the document range reference (i.e. do not show up via `childNodes`)
    * those nodes cannot be moved or removed if not through their `parentRange` reference so that these comments are special because throw errors if moved around directly (i.e. check if comment and `node.parentRange` is *not null*, throw an error)
    * those nodes can be moved around if their `parentNode` is moved around or if part of another `parentRange`
    * when the `documentRange` reference is removed or moved/inserted elsewhere, all nodes between the starting comment and the ending comment will be moved too, including sub-ranges
    * for *hydration* purposes, if a special comment node has a `parentRange` it is possible to track/map/recreate such range by checking the nextSibling that will have the same `parentRange` reference ... TBD if the content of this special node could dictate if it was the start one or the end one

I could provide a basic implementation of this idea but to me it feels like it plays well with expectations, it requires minimal changes to the current DOM primitives, it helps *hydration* stories to recreate "*fragments*" out of server side rendered HTML.

How these comments are special is likely the key-question to answer, but everything else seems to be easy to answer, imho.



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

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

Received on Wednesday, 26 March 2025 08:46:32 UTC