fix(shadowdom): remove unused nodes on redistribute

Previously, light dom nodes that were not used by any content tag
were not removed from a view on redistribute. This lead
to a bug when reusing a view from the view pool, as it
still contained stale reprojected nodes.

Fixes #1416
This commit is contained in:
Tobias Bosch
2015-04-17 20:37:23 -07:00
parent 02997f473a
commit 64ad74acbe
6 changed files with 135 additions and 18 deletions

View File

@ -34,7 +34,6 @@ export class EmulatedUnscopedShadowDomStrategy extends ShadowDomStrategy {
}
attachTemplate(el, view:viewModule.RenderView) {
DOM.clearNodes(el);
moveViewNodesIntoParent(el, view);
}

View File

@ -37,10 +37,7 @@ export class LightDom {
}
redistribute() {
var tags = this.contentTags();
if (tags.length > 0) {
redistributeNodes(tags, this.expandedDomNodes());
}
redistributeNodes(this.contentTags(), this.expandedDomNodes());
}
contentTags(): List<Content> {
@ -122,16 +119,22 @@ function redistributeNodes(contents:List<Content>, nodes:List) {
for (var i = 0; i < contents.length; ++i) {
var content = contents[i];
var select = content.select;
var matchSelector = (n) => DOM.elementMatches(n, select);
// Empty selector is identical to <content/>
if (select.length === 0) {
content.insert(nodes);
content.insert(ListWrapper.clone(nodes));
ListWrapper.clear(nodes);
} else {
var matchSelector = (n) => DOM.elementMatches(n, select);
var matchingNodes = ListWrapper.filter(nodes, matchSelector);
content.insert(matchingNodes);
ListWrapper.removeAll(nodes, matchingNodes);
}
}
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (isPresent(node.parentNode)) {
DOM.remove(nodes[i]);
}
}
}