Ensure parent node exists when stamping. Fixes #2685.

This commit is contained in:
Kevin Schaaf 2015-11-06 15:08:48 -08:00
parent 951031fccd
commit 62f2d2a298
2 changed files with 31 additions and 6 deletions

View File

@ -116,12 +116,16 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_ensureInstance: function() {
if (!this._instance) {
// TODO(sorvell): pickup stamping logic from x-repeat
this._instance = this.stamp();
var root = this._instance.root;
// TODO(sorvell): this incantation needs to be simpler.
var parent = Polymer.dom(Polymer.dom(this).parentNode);
parent.insertBefore(root, this);
var parentNode = Polymer.dom(this).parentNode;
// Guard against element being detached while render was queued
if (parentNode) {
var parent = Polymer.dom(parentNode);
// TODO(sorvell): pickup stamping logic from x-repeat
this._instance = this.stamp();
var root = this._instance.root;
// TODO(sorvell): this incantation needs to be simpler.
parent.insertBefore(root, this);
}
}
},

View File

@ -56,6 +56,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
</template>
</div>
<template id="trueif">
<template is="dom-if" if>
<div></div>
</template>
</template>
<script>
suite('nested pre-configured dom-if', function() {
@ -493,6 +499,21 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
suite('queueing race conditions', function() {
test('domif=true, attach, detach', function(done) {
var domif = document.importNode(document.querySelector('#trueif').content, true).firstElementChild;
document.body.appendChild(domif);
document.body.removeChild(domif);
setTimeout(function() {
document.body.appendChild(domif);
done();
});
});
});
</script>
</body>