From 713377ead86295207e3662890be86dfb7dc2604a Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Fri, 22 Jan 2016 16:50:01 -0800 Subject: [PATCH] Simplify fix for fragment children management. --- src/lib/dom-api-shady.html | 19 +++++++++++-------- src/lib/dom-tree-api.html | 6 +----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/lib/dom-api-shady.html b/src/lib/dom-api-shady.html index 4c08b8be1c..e2ed2c6cad 100644 --- a/src/lib/dom-api-shady.html +++ b/src/lib/dom-api-shady.html @@ -56,8 +56,7 @@ 'of this node'); } // remove node from its current position iff it's in a tree. - var isFragment = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE; - if (!isFragment) { + if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) { var parent = TreeApi.Logical.getParentNode(node); // notify existing parent that this node is being removed. if (parent) { @@ -82,11 +81,6 @@ } else { TreeApi.Composed.appendChild(container, node); } - // if a fragment provoked distribution, clean up it's actual dom. - } else if (isFragment) { - while (node.firstChild) { - node.removeChild(node.firstChild); - } } this.notifyObserver(); return node; @@ -105,8 +99,17 @@ TreeApi.Logical.recordInsertBefore(node, this.node, ref_node); } // if not distributing and not adding to host, do a fast path addition - return (this._maybeDistribute(node) || + var handled = (this._maybeDistribute(node) || this._tryRemoveUndistributedNode(node)); + // if distribution is handling this node and it's a fragment, + // the actual dom may not be removed from the fragment if some nodes + // remain undistributed so we ensure removal here. + if (handled && (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE)) { + while (node.firstChild) { + node.removeChild(node.firstChild); + } + } + return handled; }, /** diff --git a/src/lib/dom-tree-api.html b/src/lib/dom-tree-api.html index 2195423611..3fb61da781 100644 --- a/src/lib/dom-tree-api.html +++ b/src/lib/dom-tree-api.html @@ -195,11 +195,7 @@ // the act of setting this info can affect patched nodes // getters; therefore capture childNodes before patching. for (var n=node.firstChild; n; n=n.nextSibling) { - // only link in the child iff it's not already in the container's - // logical tree. - if (this.getParentNode(n) !== container) { - this._linkNode(n, container, ref_node); - } + this._linkNode(n, container, ref_node); } } else { this._linkNode(node, container, ref_node);