Addressable comments (a very small DOM parts subset)
One of the use cases that keeps coming up for DOM parts is being able to have a reference to a part of the DOM that is not directly tied to elements.
See https://github.com/WICG/declarative-partial-updates/issues/6 and https://github.com/whatwg/dom/issues/736.
The way frameworks often do this today is by creating comment nodes and keeping reference to them.
What if we implemented exactly that?
Allow some sort of string syntax inside a comment that makes it efficiently addressable from a DOM API, but it's a comment node for all other purposes (e.g. it's not stylable, doesn't affect `nth-child`, doesn't appear in `querySelector` etc).
That comment is there *only* for the purpose of being addressable.
Some use examples::
- we can have `<template contentmethod>` patches able to stream between a pair of these.
- a JS API can keep it as a stable reference into a table and replace multiple rows
The syntax inside the comment can be similar to a data URL, e.g. `marker:key=value;my-placeholder-x`, but I'm sure people here are more opionated than myself about this part.
Then there can be a JS API that efficiently addresses it, e.g. `documentOrShadowRoot.getMarkerCommentsByName("my-placeholder-x")`.
This way patching can address this comment or a range between two comments, server/client flows can update the same DOM range without requiring them to be between elements, and streaming can maintain a stable place in the DOM to stream into.
This is supposedly a lot smaller in scope than the existing DOM parts proposal, and DOM parts can perhaps be built in userland on top of this?
15 条评论