Merge pull request #3325 from Polymer/3324-kschaaf-domif-detach

Ensure dom-if moved into doc fragment is torn down. Fixes #3324
This commit is contained in:
Steve Orvell 2016-01-22 20:53:15 -08:00
commit c5ed4706ab
2 changed files with 40 additions and 1 deletions

View File

@ -73,7 +73,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
},
detached: function() {
if (!this.parentNode) {
if (!this.parentNode ||
(this.parentNode.nodeType == Node.DOCUMENT_FRAGMENT_NODE &&
(!Polymer.Settings.hasShadow ||
!(this.parentNode instanceof ShadowRoot)))) {
this._teardownInstance();
}
},

View File

@ -67,6 +67,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
</div>
</div>
<div id="removalContainer">
<template is="dom-if" if id="toBeRemoved"><div id="shouldBeRemoved"></div></template>
</div>
<script>
suite('nested pre-configured dom-if', function() {
@ -651,6 +655,38 @@ 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);
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, frag);
done();
});
} else {
done();
}
});
});