From bb85e2b6d66d25e002708b601b7361c4f06d398b Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Fri, 4 Dec 2015 15:38:20 -0800 Subject: [PATCH] Ensure dom-if in host does not restamp when host detaches. Fixes #3125. --- src/lib/template/dom-if.html | 27 +++++-- test/unit/dom-if-elements.html | 24 ++++++ test/unit/dom-if.html | 136 +++++++++++++++++++++++++++++++-- 3 files changed, 172 insertions(+), 15 deletions(-) diff --git a/src/lib/template/dom-if.html b/src/lib/template/dom-if.html index 236a0f50ba..31b68cfbdc 100644 --- a/src/lib/template/dom-if.html +++ b/src/lib/template/dom-if.html @@ -74,7 +74,9 @@ detached: function() { // TODO(kschaaf): add logic to re-stamp in attached? - this._teardownInstance(); + if (!this.parentNode) { + this._teardownInstance(); + } }, attached: function() { @@ -116,16 +118,27 @@ }, _ensureInstance: function() { - if (!this._instance) { - var parentNode = Polymer.dom(this).parentNode; - // Guard against element being detached while render was queued - if (parentNode) { - var parent = Polymer.dom(parentNode); + var parentNode = Polymer.dom(this).parentNode; + // Guard against element being detached while render was queued + if (parentNode) { + var parent = Polymer.dom(parentNode); + 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. parent.insertBefore(root, this); + } else { + var c$ = this._instance._children; + if (c$ && c$.length) { + // Detect case where dom-if was re-attached in new position + var lastChild = Polymer.dom(this).previousSibling; + if (lastChild !== c$[c$.length-1]) { + for (var i=0, n; (i + + + + + diff --git a/test/unit/dom-if.html b/test/unit/dom-if.html index 1050514d99..1f379e454c 100644 --- a/test/unit/dom-if.html +++ b/test/unit/dom-if.html @@ -56,9 +56,16 @@ - +
+ + +
+
+