Skip to content

Commit eac9249

Browse files
authored
Update patching-explainer.md
1 parent 65f4ecc commit eac9249

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

patching-explainer.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,42 @@ The new `<?marker>`, `<?start>`, and `<?end>` nodes would be represented with th
130130

131131
To allow scripts to use markers in the same way a declarative patching would, an `element.markerRange("list")` method is introduced, returning a `Range` object spanning the same nodes that would be replaced.
132132

133-
## Script-initiated patching
133+
## Interaction with script-initiated patching
134+
135+
Streaming into an element using script is being pursued [separately](https://github.com/WICG/declarative-partial-updates/blob/main/dynamic-markup-revamped-explainer.md), but will also work with patching.
136+
When `<template for>` appears in the streamed HTML, those patches can apply to descendants of element on which `streamAppendHTMLUnsafe()` was called.
137+
138+
For example:
139+
140+
```html
141+
<!-- load the document shell -->
142+
<div id=container>
143+
<div marker="results more">
144+
<?start name=results>
145+
Loading...
146+
</div>
147+
</div>
148+
<!-- later, as a response to navigation or a click or anything... -->
149+
<script>
150+
async function update_results() {
151+
const writer = container.streamAppendHTMLUnsafe().getWriter();
152+
await writer.write(`
153+
<template for=result>
154+
<?start name=results>
155+
Result 1
156+
<?marker name=more>
157+
</template>
158+
`);
159+
await writer.write(`
160+
<template for=more>
161+
Result 2
162+
<?marker name=more>
163+
</template>
164+
`);
165+
}
166+
</script>
167+
```
134168

135-
`streamHTMLUnsafe()` is being pursued as a [separate proposal](https://github.com/whatwg/html/issues/2142), but will also work with patching. When `<template contentmethod>` appears in the streamed HTML, those patches can apply to descendants of element on which `streamHTMLUnsafe()` was called.
136169

137170
## Potential enhancement
138171

0 commit comments

Comments
 (0)