Re: [whatwg/dom] replaceChild() has odd mutation observer behavior after #754 (#814)

Sorry, it looks like I have gotten myself confused. The correct patch should be the following:

<details>

```patch
diff --git a/lib/jsdom/living/nodes/Document-impl.js b/lib/jsdom/living/nodes/Document-impl.js
index 94f8d484..3b486d84 100644
--- a/lib/jsdom/living/nodes/Document-impl.js
+++ b/lib/jsdom/living/nodes/Document-impl.js
@@ -816,7 +816,7 @@ class DocumentImpl extends NodeImpl {
   }
 
   // https://dom.spec.whatwg.org/#concept-node-adopt
-  _adoptNode(node) {
+  _adoptNode(node, doItAnyway = false) {
     const newDocument = this;
     const oldDocument = node._ownerDocument;
 
@@ -827,6 +827,9 @@ class DocumentImpl extends NodeImpl {
 
     if (oldDocument !== newDocument) {
       for (const inclusiveDescendant of shadowIncludingInclusiveDescendantsIterator(node)) {
+        if (!doItAnyway && DocumentFragment.isImpl(node) && node._host) {
+          continue;
+        }
         inclusiveDescendant._ownerDocument = newDocument;
       }
 
diff --git a/lib/jsdom/living/nodes/HTMLTemplateElement-impl.js b/lib/jsdom/living/nodes/HTMLTemplateElement-impl.js
index b0a2405b..1f829e49 100644
--- a/lib/jsdom/living/nodes/HTMLTemplateElement-impl.js
+++ b/lib/jsdom/living/nodes/HTMLTemplateElement-impl.js
@@ -43,7 +43,7 @@ class HTMLTemplateElementImpl extends HTMLElementImpl {
   // https://html.spec.whatwg.org/multipage/scripting.html#template-adopting-steps
   _adoptingSteps() {
     const doc = this._appropriateTemplateContentsOwnerDocument(this._ownerDocument);
-    doc._adoptNode(this._templateContents);
+    doc._adoptNode(this._templateContents, /* doItAnyway= */ true);
   }
 
   get content() {
```
</details>

In terms of tests, `template-element/template-content-hierarcy.html` works, `custom-elements/adopted-callback.html` has the same result as before, and `dom/nodes/adoption.window.js` has:

```
Failed in "appendChild() and DocumentFragment with host": 
assert_equals: expected Document node with 2 children but got Document node with 0 children

Failed in "appendChild() and DocumentFragment": 
assert_equals: expected Document node with 0 children but got Document node with 2 children

Failed in "appendChild() and ShadowRoot": 
assert_equals: expected Document node with 2 children but got Document node with 0 children
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/814#issuecomment-605083678

Received on Friday, 27 March 2020 16:06:58 UTC