diff options
-rw-r--r-- | components/script/dom/documentorshadowroot.rs | 2 | ||||
-rw-r--r-- | components/script/dom/element.rs | 3 | ||||
-rw-r--r-- | tests/wpt/meta/MANIFEST.json | 7 | ||||
-rw-r--r-- | tests/wpt/tests/shadow-dom/getElementById-dynamic-002.html | 20 |
4 files changed, 30 insertions, 2 deletions
diff --git a/components/script/dom/documentorshadowroot.rs b/components/script/dom/documentorshadowroot.rs index 96323156ba8..c814b75cfda 100644 --- a/components/script/dom/documentorshadowroot.rs +++ b/components/script/dom/documentorshadowroot.rs @@ -303,7 +303,7 @@ impl DocumentOrShadowRoot { root: DomRoot<Node>, ) { debug!("Adding named element {:p}: {:p} id={}", self, element, id); - assert!(element.upcast::<Node>().is_connected()); + assert!(element.upcast::<Node>().is_connected_to_tree()); assert!(!id.is_empty()); let mut id_map = id_map.borrow_mut(); let elements = id_map.entry(id.clone()).or_default(); diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index ca7effd3e09..be31e9ba122 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -3510,8 +3510,9 @@ impl VirtualMethods for Element { None } }); + let containing_shadow_root = self.containing_shadow_root(); - if node.is_connected() { + if node.is_connected_to_tree() { let value = attr.value().as_atom().clone(); match mutation { AttributeMutation::Set(old_value) => { diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index 9d5076c170a..29079cda314 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -766457,6 +766457,13 @@ {} ] ], + "getElementById-dynamic-002.html": [ + "8fb1934c60753c39c081fa97987bbdf1cc68a521", + [ + null, + {} + ] + ], "historical.html": [ "4fa8be1dbc9537b904d51b74e8de37dc36a471d6", [ diff --git a/tests/wpt/tests/shadow-dom/getElementById-dynamic-002.html b/tests/wpt/tests/shadow-dom/getElementById-dynamic-002.html new file mode 100644 index 00000000000..8fb1934c607 --- /dev/null +++ b/tests/wpt/tests/shadow-dom/getElementById-dynamic-002.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>Shadow DOM: Modifying an element ID inside a disconnected shadow root does not break getElementById</title> +<link rel="help" href="https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid"> +<link rel="author" name="Simon Wülker"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="host"></div> +<script> +test(function() { + let host = document.getElementById("host"); + host.attachShadow({ mode: "open" }).innerHTML = `<div id="test-id"></div>`; + let element = host.shadowRoot.getElementById("test-id"); + assert_true(!!element); + + host.remove(); + host.shadowRoot.getElementById("test-id").id = "new-id"; + + assert_equals(host.shadowRoot.getElementById("new-id"), element); +}, "ShadowRoot.getElementById works on elements whose id was modified after the root was disconnected"); +</script> |