Skip to content

Commit

Permalink
Ensure parent node exists when stamping. Fixes #2685.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Nov 6, 2015
1 parent 951031f commit 62f2d2a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lib/template/dom-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,16 @@

_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);
}
}
},

Expand Down
21 changes: 21 additions & 0 deletions test/unit/dom-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
</template>
</div>

<template id="trueif">
<template is="dom-if" if>
<div></div>
</template>
</template>

<script>

suite('nested pre-configured dom-if', function() {
Expand Down Expand Up @@ -493,6 +499,21 @@

});

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>
Expand Down

0 comments on commit 62f2d2a

Please sign in to comment.