diff --git a/src/lib/dom-api.html b/src/lib/dom-api.html index 7295e4422a..944234ea43 100644 --- a/src/lib/dom-api.html +++ b/src/lib/dom-api.html @@ -238,8 +238,9 @@ _tryRemoveUndistributedNode: function(node) { if (this.node.shadyRoot) { - if (node._composedParent) { - nativeRemoveChild.call(node._composedParent, node); + var parent = getComposedParent(node); + if (parent) { + nativeRemoveChild.call(parent, node); } return true; } @@ -289,7 +290,7 @@ this._updateInsertionPoints(root.host); this._lazyDistribute(root.host); } else if (ensureComposedRemoval) { - removeFromComposedParent(node._composedParent, node); + removeFromComposedParent(getComposedParent(node), node); } }, @@ -572,8 +573,7 @@ parentNode: { get: function() { return this.node._lightParent || - (this.node.__patched ? this.node._composedParent : - this.node.parentNode); + getComposedParent(this.node); }, configurable: true }, @@ -909,7 +909,10 @@ } else { addNodeToComposedChildren(node, parent, children, i); } + } + function getComposedParent(node) { + return node.__patched ? node._composedParent : node.parentNode; } function addNodeToComposedChildren(node, parent, children, i) { @@ -956,6 +959,7 @@ return { getLightChildren: getLightChildren, + getComposedParent: getComposedParent, getComposedChildren: getComposedChildren, removeFromComposedParent: removeFromComposedParent, saveLightChildrenIfNeeded: saveLightChildrenIfNeeded, diff --git a/src/mini/shady.html b/src/mini/shady.html index 0caa80eab4..2b281a6841 100644 --- a/src/mini/shady.html +++ b/src/mini/shady.html @@ -320,6 +320,8 @@ composed.splice(j, 0, n); } } + // ensure composed parent is set + ensureComposedParent(container, children); }, _matchesContentSelect: function(node, contentElement) { @@ -364,6 +366,7 @@ var matchesSelector = Polymer.DomApi.matchesSelector; var hasInsertionPoint = Polymer.DomApi.hasInsertionPoint; var getComposedChildren = Polymer.DomApi.getComposedChildren; + var getComposedParent = Polymer.DomApi.getComposedParent; var removeFromComposedParent = Polymer.DomApi.removeFromComposedParent; function distributeNodeInto(child, insertionPoint) { @@ -434,8 +437,10 @@ } } - function getComposedParent(node) { - return node.__patched ? node._composedParent : node.parentNode; + function ensureComposedParent(parent, children) { + for (var i=0, n; i < children.length; i++) { + children[i]._composedParent = parent; + } } // returns the host that's the top of this host's distribution tree