diff --git a/src/lib/template/dom-if.html b/src/lib/template/dom-if.html index 8952e8be5a..01dce89f90 100644 --- a/src/lib/template/dom-if.html +++ b/src/lib/template/dom-if.html @@ -82,8 +82,12 @@ }, detached: function() { - if (!this.parentNode || - (this.parentNode.nodeType == Node.DOCUMENT_FRAGMENT_NODE && + var parentNode = this.parentNode; + if (parentNode && parentNode.localName == this.is) { + parentNode = Polymer.dom(parentNode).parentNode; + } + if (!parentNode || + (parentNode.nodeType == Node.DOCUMENT_FRAGMENT_NODE && (!Polymer.Settings.hasShadow || !(this.parentNode instanceof ShadowRoot)))) { this._teardownInstance(); diff --git a/test/unit/dom-if.html b/test/unit/dom-if.html index ef4a1baddd..fc98e3a221 100644 --- a/test/unit/dom-if.html +++ b/test/unit/dom-if.html @@ -89,15 +89,22 @@ assert.equal(stamped[0].parentNode, document.body); }); - test('remove & re-add works correctly', function() { + test('remove & re-add works correctly', function(done) { var wrapper = hybridDomIfWrapper; + var domIf = hybridDomIf; Polymer.dom(document.body).removeChild(wrapper); - Polymer.dom(document.body).appendChild(wrapper); CustomElements.takeRecords(); - hybridDomIf.render(); + domIf.render(); var stamped = Array.from(document.querySelectorAll('[hybrid-stamped]')); - assert.equal(stamped.length, 1); - assert.equal(stamped[0].parentNode, document.body); + assert.equal(stamped.length, 0); + Polymer.dom(removalContainer).appendChild(wrapper); + CustomElements.takeRecords(); + setTimeout(function() { + stamped = Array.from(document.querySelectorAll('[hybrid-stamped]')); + assert.equal(stamped.length, 1); + assert.equal(stamped[0].parentNode, removalContainer); + done(); + }); }); test('children removed correctly', function() { diff --git a/test/unit/dom-repeat.html b/test/unit/dom-repeat.html index 7ff3540dc9..fb1b841b31 100644 --- a/test/unit/dom-repeat.html +++ b/test/unit/dom-repeat.html @@ -3898,21 +3898,38 @@