Skip to content

Commit

Permalink
Ensure fragments added via Polymer.dom always have elements removed, …
Browse files Browse the repository at this point in the history
…even when distribution does not select those elements.
  • Loading branch information
Steven Orvell committed Jan 23, 2016
1 parent 9f2464d commit 101eb3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/dom-api-shady.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
'of this node');
}
// remove node from its current position iff it's in a tree.
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
var isFragment = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
if (!isFragment) {
var parent = TreeApi.Logical.getParentNode(node);
// notify existing parent that this node is being removed.
if (parent) {
Expand All @@ -81,6 +82,11 @@
} 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;
Expand Down
10 changes: 10 additions & 0 deletions test/unit/polymer-dom-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,16 @@
});
});

test('adding a document fragment always clears nodes in the fragment', function() {
var x = document.createElement('x-dist-star');
var frag = document.createDocumentFragment();
frag.appendChild(document.createTextNode('hi'));
frag.appendChild(document.createElement('div'));
Polymer.dom(x).appendChild(frag);
Polymer.dom.flush();
assert.equal(frag.childNodes.length, 0);
});

});


Expand Down

0 comments on commit 101eb3d

Please sign in to comment.