Skip to content

Commit 530f687

Browse files
noamrchromium-wpt-export-bot
authored andcommitted
Document patching: initial support
Add runtime flag + very basic support for <template patchfor> Chromestatus: https://chromestatus.com/feature/5111042975465472?gate=5122079833456640 Bug: 431374376 Change-Id: I6cb86725c51fc4416516c628e153493bc4073228 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6732978 Reviewed-by: Philip Jägenstedt <[email protected]> Commit-Queue: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1486491}
1 parent 760d5bc commit 530f687

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE HTML>
2+
<meta charset="utf-8" />
3+
<title>HTML partial updates: patch should appear after its target</title>
4+
<link rel=help href="https://github.com/WICG/declarative-partial-updates">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<template patchfor="placeholder">New content</template>
9+
<div id="placeholder">Old content</div>
10+
<script>
11+
test(() => {
12+
assert_equals(document.querySelector("#placeholder").innerText, "Old content");
13+
assert_equals(document.querySelector("template[patchfor=placeholder]").content.textContent, "New content",
14+
"<template patchfor> without a match should parse normally");
15+
}, "<template patchfor> should apply directly to its target");
16+
</script>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE HTML>
2+
<meta charset="utf-8" />
3+
<title>HTML partial updates</title>
4+
<link rel=help href="https://github.com/WICG/declarative-partial-updates">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<div id="placeholder">Old content</div>
9+
<template patchfor="placeholder">New content</template>
10+
<script>
11+
test(() => {
12+
assert_equals(document.querySelector("#placeholder").innerText, "New content");
13+
assert_equals(document.querySelector("template[patchfor]"), null, "<template patchfor> with a match should not attach");
14+
}, "<template patchfor> should apply directly to its target");
15+
16+
test(() => {
17+
const doc = document.implementation.createHTMLDocument();
18+
doc.write('<div id="placeholder">Old content</div>');
19+
assert_equals(doc.querySelector("#placeholder").innerText, "Old content");
20+
doc.write('<template patchfor="placeholder">');
21+
assert_equals(doc.querySelector("template"), null);
22+
assert_equals(doc.querySelector("#placeholder").innerText, "");
23+
doc.write('New');
24+
assert_equals(doc.querySelector("#placeholder").innerText, "New");
25+
doc.write(' content</template>');
26+
assert_equals(doc.querySelector("#placeholder").innerText, "New content");
27+
assert_equals(doc.querySelector("template"), null);
28+
}, "<template patchfor> should work when chunked");
29+
30+
</script>

0 commit comments

Comments
 (0)