Skip to content

Commit 8b7c020

Browse files
authored
Update patching-explainer.md
1 parent 6166fab commit 8b7c020

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

patching-explainer.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Patching (Partial, interleaved HTML streaming)
1+
# Interleaved HTML streaming (patching)
22

33
## Motivation
44
Streaming of HTML existed from the early days of the web, serving an important purpose for perceieved performance when loading long articles etc.
@@ -54,17 +54,31 @@ In addition to invoking streaming using script, this proposal includes patching
5454
parses its content as raw text, finds the target element using attributes, and reroutes the raw text content to the target element:
5555

5656
```html
57-
<section outlet=gallery>Loading...</section>
57+
<section contentname=gallery>Loading...</section>
5858

5959
<!-- later -->
60-
<template patchforr=gallery>Actual gallery content</template>
60+
<template contentfor=gallery>Actual gallery content</template>
6161
```
6262

6363
A few details about interleaved patching:
64-
- If an outlet is not found, the patching element remains in the DOM.
65-
- The first patch for a target in the document stream replaces its content, and the next ones append. This allows interleaved streaming into the same target.
64+
- If an outlet (an element with `contentname`) is not found, the patch template remains in the DOM.
6665
- If the patching element is not a direct child of `<body>`, the outlet has to have a common ancestor with the patching element's parent.
67-
- The patching element has to be in the same tree scope as the outlet.
66+
- The patch template has to be in the same tree scope as the outlet.
67+
- By default, the first patch in the stream replaces the entire contents of the outlet, like `replaceChildren`, and the next ones behave like `append`.
68+
69+
## Manipulating without replacing: `contentcommand`
70+
71+
To allow the patch to manipulate the DOM without replacing all the children, A `contentcommand` attribute
72+
(values `replaceChildren`, `replaceWith`, `append`, `prepend`, `before`, `after`) can control where the contents of the patch are positioned.
73+
74+
An empty string means the default behavior (`replaceChildren` at start, then `append`).
75+
76+
Those behave with the same semantics as the equivalent DOM manipulation methods, and specifically as defined in https://github.com/whatwg/html/issues/11669.
77+
78+
## Avoiding overwriting with identical content
79+
80+
Some content might need to remain unchanged in certain conditions. For example, displaying a chat widget in all pages but the home, but not reloading it between pages.
81+
For this, both the outlet and the patch can have a `contentrevision` attribute. If those match, the content is not applied.
6882

6983
## Reflection
7084

@@ -73,7 +87,7 @@ Besides applying a patch, there should be a few ways to reflect about the curren
7387
### CSS reflection
7488
See https://github.com/w3c/csswg-drafts/issues/12579 and https://github.com/w3c/csswg-drafts/issues/12578.
7589

76-
Suggesting to add a couple of pseudo-classes: `:patching` and `:patch-pending`, that reflect the patching status of an element, in addition to a pseudo-class that reflects that an element's parser state is open (regardless of patching).
90+
Suggesting to add a couple of pseudo-classes: `:updating` and `:pending`, that reflect the patching status of an element, in addition to a pseudo-class that reflects that an element's parser state is open (regardless of patching).
7791

7892
### JS status
7993

@@ -88,10 +102,6 @@ Note that the HTML sanitizer works closely with the HTML parser, so it shouldn't
88102

89103
In addition, [Trusted types](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) would need streaming support in its policy, potentially by injecting a `TransformStream` into the patch. See https://github.com/w3c/trusted-types/issues/594.
90104

91-
## Enhancement - replace range instead of whole contents
92-
Some use cases for out of order streaming require replacing parts of the element's children but not other parts, e.g. adding `<meta>` tags to the `<head>` or replacing only some `<option>`s in a `<select>`.
93-
To achive that, the script and HTML APIs would receive an optional children range to replace, e.g. by having `patchstartafter` and `patchendbefore` attributes, and also allow similar options in the various JS APIs.
94-
95105
## Enhancement - JS API for interleaved patching
96106
In addition to invoking interleaved patching as part of the main response, allow parsing an HTML stream and extracting patches from it into an existing element:
97107
```js

0 commit comments

Comments
 (0)