diff --git a/src/lib/dom-api.html b/src/lib/dom-api.html
index 929c1ac912..b2a4b53429 100644
--- a/src/lib/dom-api.html
+++ b/src/lib/dom-api.html
@@ -65,10 +65,10 @@
// 3. node is (host of container needs distribution)
appendChild: function(node) {
var handled;
- // if a is added, make sure it's parent has logical info.
- this._ensureContentLogicalInfo(node);
this._removeNodeFromHost(node, true);
if (this._nodeIsInLogicalTree(this.node)) {
+ // if a is added, make sure it's parent has logical info.
+ this._ensureContentLogicalInfo(node);
this._addLogicalInfo(node, this.node);
this._addNodeToHost(node);
handled = this._maybeDistribute(node, this.node);
@@ -90,10 +90,10 @@
return this.appendChild(node);
}
var handled;
- // if a is added, make sure it's parent has logical info.
- this._ensureContentLogicalInfo(node);
this._removeNodeFromHost(node, true);
if (this._nodeIsInLogicalTree(this.node)) {
+ // if a is added, make sure it's parent has logical info.
+ this._ensureContentLogicalInfo(node);
var children = this.childNodes;
var index = children.indexOf(ref_node);
if (index < 0) {
@@ -242,11 +242,10 @@
}
},
- // a node is in a shadyRoot, is a shadyRoot,
- // or has a lightParent
+ // a node has logical info associated with it
_nodeIsInLogicalTree: function(node) {
- return Boolean((node._lightParent !== undefined) || node._isShadyRoot ||
- node.shadyRoot);
+ return Boolean(node._lightParent !== undefined ||
+ node._lightChildren !== undefined);
},
_ensureContentLogicalInfo: function(node) {
@@ -270,11 +269,16 @@
// NOTE: if `ensureComposedRemoval` is true then the node should be
// removed from its composed parent.
_removeNodeFromHost: function(node, ensureComposedRemoval) {
+ // note that it's possible for both the node's host and its parent
+ // to require distribution... both cases are handled here.
var hostNeedsDist;
var root;
var parent = node._lightParent;
if (parent) {
+ // distribute node's parent iff needed
+ factory(node)._distributeParent();
root = this._ownerShadyRootForNode(node);
+ // remove node from root and distribute it iff needed
if (root) {
root.host._elementRemove(node);
hostNeedsDist = this._removeDistributedChildren(root, node);
@@ -938,7 +942,7 @@
}
function hasInsertionPoint(root) {
- return Boolean(root._insertionPoints.length);
+ return Boolean(root && root._insertionPoints.length);
}
var p = Element.prototype;
diff --git a/test/unit/polymer-dom-content.html b/test/unit/polymer-dom-content.html
index 48ca1fe79e..a9665de2b8 100644
--- a/test/unit/polymer-dom-content.html
+++ b/test/unit/polymer-dom-content.html
@@ -20,7 +20,7 @@
x-dist
-
+