Skip to content

Commit ca3b40b

Browse files
noamrchromium-wpt-export-bot
authored andcommitted
Element.currentPatch reflects current status of patchfor operations
Added an IDL-exposed PatchStatus, which reflects the status of an ongoing patch operation initiated by <template patchfor>. The exposed interface exposes the detached template element, as well as a promise that resolves when the patching is complete. To be added: rejecting the promise on errors, allowing to abort the patch via the PatchStatus interface. Bug: 431374376 Change-Id: I496447296b3f49e5f197d7e4148e7e8ffda604cb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6757120 Reviewed-by: Philip Jägenstedt <foolip@chromium.org> Reviewed-by: Noam Rosenthal <nrosenthal@google.com> Commit-Queue: Noam Rosenthal <nrosenthal@google.com> Cr-Commit-Position: refs/heads/main@{#1489336}
1 parent 2bc680c commit ca3b40b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE HTML>
2+
<meta charset="utf-8" />
3+
<title>HTML partial updates - reflection via element.currentPatch</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+
<script>
9+
promise_test(async t => {
10+
const doc = document.implementation.createHTMLDocument();
11+
doc.write('<div id="placeholder">Old content</div>');
12+
const placeholder = doc.getElementById("placeholder");
13+
assert_equals(placeholder.currentPatch, null, "no patch active, currentPatch should be null");
14+
doc.write('<template id=patchy patchfor="placeholder">');
15+
const {currentPatch} = placeholder;
16+
assert_true(currentPatch instanceof PatchStatus);
17+
const {finished, source} = currentPatch;
18+
assert_true(source instanceof HTMLTemplateElement);
19+
assert_equals(source.id, "patchy");
20+
let did_finish = false;
21+
finished.then((() => {did_finish = true}));
22+
await new Promise(resolve => t.step_timeout(resolve, 100));
23+
assert_false(did_finish, "we are not finished yet");
24+
doc.write("<p>content</p>");
25+
await new Promise(resolve => t.step_timeout(resolve, 100));
26+
assert_false(did_finish, "we are not finished yet");
27+
assert_equals(placeholder.currentPatch, currentPatch);
28+
doc.write("</template>");
29+
assert_equals(placeholder.currentPatch, null, "template is closed, currentPatch is null");
30+
const result = await finished;
31+
assert_equals(result, undefined);
32+
}, "currentPatch lifecycle");
33+
34+
</script>

0 commit comments

Comments
 (0)