Skip to content

Commit 713377e

Browse files
author
Steven Orvell
committed
Simplify fix for fragment children management.
1 parent 25da63d commit 713377e

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/lib/dom-api-shady.html

+11-8
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
'of this node');
5757
}
5858
// remove node from its current position iff it's in a tree.
59-
var isFragment = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
60-
if (!isFragment) {
59+
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
6160
var parent = TreeApi.Logical.getParentNode(node);
6261
// notify existing parent that this node is being removed.
6362
if (parent) {
@@ -82,11 +81,6 @@
8281
} else {
8382
TreeApi.Composed.appendChild(container, node);
8483
}
85-
// if a fragment provoked distribution, clean up it's actual dom.
86-
} else if (isFragment) {
87-
while (node.firstChild) {
88-
node.removeChild(node.firstChild);
89-
}
9084
}
9185
this.notifyObserver();
9286
return node;
@@ -105,8 +99,17 @@
10599
TreeApi.Logical.recordInsertBefore(node, this.node, ref_node);
106100
}
107101
// if not distributing and not adding to host, do a fast path addition
108-
return (this._maybeDistribute(node) ||
102+
var handled = (this._maybeDistribute(node) ||
109103
this._tryRemoveUndistributedNode(node));
104+
// if distribution is handling this node and it's a fragment,
105+
// the actual dom may not be removed from the fragment if some nodes
106+
// remain undistributed so we ensure removal here.
107+
if (handled && (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE)) {
108+
while (node.firstChild) {
109+
node.removeChild(node.firstChild);
110+
}
111+
}
112+
return handled;
110113
},
111114

112115
/**

src/lib/dom-tree-api.html

+1-5
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@
195195
// the act of setting this info can affect patched nodes
196196
// getters; therefore capture childNodes before patching.
197197
for (var n=node.firstChild; n; n=n.nextSibling) {
198-
// only link in the child iff it's not already in the container's
199-
// logical tree.
200-
if (this.getParentNode(n) !== container) {
201-
this._linkNode(n, container, ref_node);
202-
}
198+
this._linkNode(n, container, ref_node);
203199
}
204200
} else {
205201
this._linkNode(node, container, ref_node);

0 commit comments

Comments
 (0)