diff --git a/src/lib/template/dom-if.html b/src/lib/template/dom-if.html index f5123338..500f56f3 100644 --- a/src/lib/template/dom-if.html +++ b/src/lib/template/dom-if.html @@ -73,7 +73,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN }, detached: function() { - if (!this.parentNode || this.parentNode.nodeType == Node.DOCUMENT_FRAGMENT_NODE) { + if (!this.parentNode || + (this.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 f2d0fec7..0f555472 100644 --- a/test/unit/dom-if.html +++ b/test/unit/dom-if.html @@ -657,14 +657,40 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN test('move into doc fragment', function(done) { var el = shouldBeRemoved; + assert.equal(el.parentNode, removalContainer); var frag = document.createDocumentFragment(); Polymer.dom(frag).appendChild(toBeRemoved); setTimeout(function() { assert.equal(el.parentNode, null); - done(); + Polymer.dom(removalContainer).appendChild(frag); + setTimeout(function() { + assert.equal(shouldBeRemoved.parentNode, removalContainer); + done(); + }); }); }); + test('move into shadow root', function(done) { + if (Polymer.Settings.hasShadow) { + var el = shouldBeRemoved; + assert.equal(el.parentNode, removalContainer); + var div = document.createElement('div'); + document.body.appendChild(div); + var frag = div.createShadowRoot(); + Polymer.dom(frag).appendChild(toBeRemoved); + setTimeout(function() { + assert.equal(el.parentNode, null); + Polymer.dom(removalContainer).appendChild(frag); + setTimeout(function() { + assert.equal(shouldBeRemoved.parentNode, removalContainer); + done(); + }); + }); + } else { + done(); + } + }); + });