Skip to content

Commit 572cf4b

Browse files
mfreed7moz-wptsync-bot
authored andcommittedFeb 2, 2024
Bug 1876932 [wpt PR 44247] - Make shallow clone work when clonable is true, a=testonly
Automatic update from web-platform-tests Make shallow clone work when clonable is true This did not previously work correctly, but now, this will work: const shadow = host.attachShadow({mode:'open', clonable:true}); host.cloneNode(false); The behavior is for the shadow root to be deep-cloned, even though the `deep` argument to `cloneNode()` is `false`. See this discussion for more context: whatwg/dom#1249 and this summary of the consensus: whatwg/dom#1249 (comment) Bug: 1510466 Change-Id: I8a9de78044785675cd6bbac93d9b26286445ac8d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5242239 Reviewed-by: David Baron <[email protected]> Auto-Submit: Mason Freed <[email protected]> Commit-Queue: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1254312} -- wpt-commits: bf7b1d88809248c70531b45d7c202a1fc7993d2d wpt-pr: 44247
1 parent 6f6b9b8 commit 572cf4b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed
 

‎testing/web-platform/tests/shadow-dom/shadow-root-clonable.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<link rel='author' href='mailto:krosylight@mozilla.com'>
44
<link rel='author' href='mailto:masonf@chromium.org'>
55
<link rel='help' href='https://dom.spec.whatwg.org/#shadowroot-clonable'>
6+
<link rel='help' href='https://github.com/whatwg/dom/issues/1249#issuecomment-1917772229'>
67
<script src='/resources/testharness.js'></script>
78
<script src='/resources/testharnessreport.js'></script>
89

@@ -11,14 +12,22 @@
1112
test(() => {
1213
const div = document.createElement("div");
1314
const root = div.attachShadow({ mode: "open", clonable: true });
14-
root.appendChild(document.createElement("input"));
15+
root.innerHTML = '<input><div><span></span></div>';
1516
assert_true(root.clonable, "clonable attribute");
1617

1718
const clone = div.cloneNode(true);
1819
const clonedRoot = clone.shadowRoot;
1920
assert_true(clonedRoot.clonable, "clone gets the same clonable state");
20-
assert_equals(clonedRoot.children.length, 1, "children count");
21+
assert_equals(clonedRoot.children.length, 2, "children count");
2122
assert_equals(clonedRoot.children[0].localName, "input", "children content");
23+
assert_equals(clonedRoot.children[1].firstElementChild.localName, "span", "grandchildren content");
24+
25+
const shallowClone = div.cloneNode(false);
26+
const shallowClonedRoot = shallowClone.shadowRoot;
27+
assert_true(shallowClonedRoot.clonable, "clone gets the same clonable state");
28+
assert_equals(shallowClonedRoot.children.length, 2, "shallow clone still deep-clones the shadow root");
29+
assert_equals(shallowClonedRoot.children[0].localName, "input", "shadow children content");
30+
assert_equals(shallowClonedRoot.children[1].firstElementChild.localName, "span", "shadow grandchildren content");
2231
}, "attachShadow with clonable: true");
2332

2433
for (const clonable of [false, undefined]) {

0 commit comments

Comments
 (0)
Please sign in to comment.