Skip to content

Commit b6279b1

Browse files
authored
Merge pull request #79 from WICG/start-end-model
Tweak the markers start/end option a bit
2 parents c51f6c4 + a8b1792 commit b6279b1

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

patching-explainer.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,16 @@ The patches uses a single marker node:
206206

207207
##### Markers with start/end attributes
208208

209-
This alternative adds `start` and `end` boolean attributes to the marker nodes, so that the start/end of a range are defined by the markers, not attributes on `<template>`.
209+
This alternative leans into markers as the way to define content ranges, using optional `start` and `end` boolean attributes. The range to replace is defined by the `contentfor` attribute on `<template>`, and the range is determined as such:
210210

211-
This makes it possible to replace a `<title>` element.
211+
- First find the first marker in the tree with the right name
212+
- If there's no `start` or `end` attribute, or both are present, that marker itself is the whole range
213+
- If there's a `start` attribute, traverse next siblings until a matching marker with `end` is found, or the end of the sibling list
214+
- If there's an `end` attribute, traverse previous siblings until a matching marker with `start` is found, or the start of the sibling list
215+
216+
Everything in that range is removed (including the marker nodes) before adding new nodes from the `<template>` element.
217+
218+
This makes it possible to replace a `<title>` element:
212219

213220
<details>
214221
<summary>Example</summary>
@@ -220,22 +227,26 @@ This makes it possible to replace a `<title>` element.
220227
<?marker name="metadata" end?>
221228
</head>
222229

223-
<template contentname="metadata">
230+
<template contentfor="metadata">
224231
<title>Page 2</title>
225232
</template>
226233
```
227234

228235
</details>
229236

230-
Details around `<title>` and the RCDATA tokenizer state are the main reason that the tag name needs to be repeated in other alterantives, but this isn't needed in this option, the children of `<template>` elements are just the new content. The `contentname` attribute can refer to either marker node(s) or an element.
237+
Details around `<title>` and the RCDATA tokenizer state are the main reason that the tag name needs to be repeated in other alterantives, but this isn't needed in this option, the children of `<template>` elements are just the new content.
231238

232-
When `start` and `end` aren't used, the marker node is replaced. The interleaved patching example then becomes:
239+
The interleaved patching example then becomes:
233240

234241
<details>
235242
<summary>Example</summary>
236243

237244
```html
238-
<template contentname=search-results>
245+
<!-- explicit markers are needed *inside* the element being patched. end markers are omitted -->
246+
<div><?marker name=product-carousel start?>Loading...</div>
247+
<div><?marker name=search-results start?>Loading...</div>
248+
249+
<template contentfor=search-results>
239250
<p>first result</p>
240251
<!-- add markers to allow for "append" -->
241252
<?marker name=search-results-more?>
@@ -258,6 +269,11 @@ When `start` and `end` aren't used, the marker node is replaced. The interleaved
258269

259270
</details>
260271

272+
Possible ergonomic additions this option:
273+
274+
- Targeting elements (not just markers) and replacing all child nodes by default
275+
- A `keep` attribute on markers that would avoid removing them
276+
261277
## Script-initiated patching
262278

263279
`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.

0 commit comments

Comments
 (0)