Skip to content

Commit

Permalink
Merge pull request #2696 from Polymer/2685-kschaaf-detached-domif
Browse files Browse the repository at this point in the history
Ensure parent node exists when stamping. Fixes #2685.
  • Loading branch information
Steve Orvell committed Nov 6, 2015
2 parents 951031f + fa96ff3 commit 07d39a1
Show file tree
Hide file tree
Showing 2 changed files with 30 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
20 changes: 20 additions & 0 deletions test/unit/dom-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
</template>
</div>

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

<script>

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

});

suite('queueing race conditions', function() {

test('domif=true, attach, detach', function(done) {
var domif = document.querySelector('#simple');
domif.if = true;
document.body.appendChild(domif);
document.body.removeChild(domif);
setTimeout(function() {
document.body.appendChild(domif);
done();
});
});

});


</script>

</body>
Expand Down

0 comments on commit 07d39a1

Please sign in to comment.