From 53053eb447686ac9a66b8035a958584ac2e40ecf Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Fri, 14 Apr 2017 17:59:21 -0700 Subject: [PATCH] Add 2.x hybrid affordances for stamping template content. Fixes #4536 --- src/lib/template/dom-bind.html | 12 +++++-- src/lib/template/dom-if.html | 13 ++++++-- src/lib/template/dom-repeat.html | 7 ++++ test/unit/dom-bind.html | 37 +++++++++++++++++++-- test/unit/dom-if.html | 39 ++++++++++++++++++---- test/unit/dom-repeat.html | 55 +++++++++++++++++++++++--------- 6 files changed, 134 insertions(+), 29 deletions(-) diff --git a/src/lib/template/dom-bind.html b/src/lib/template/dom-bind.html index c9561c9105..a7cdf4bccd 100644 --- a/src/lib/template/dom-bind.html +++ b/src/lib/template/dom-bind.html @@ -108,8 +108,16 @@ }, _insertChildren: function() { - var parentDom = Polymer.dom(Polymer.dom(this).parentNode); - parentDom.insertBefore(this.root, this); + var refNode; + var parentNode = Polymer.dom(this).parentNode; + // Affordance for 2.x hybrid mode + if (parentNode.localName == this.is) { + refNode = parentNode; + parentNode = Polymer.dom(parentNode).parentNode; + } else { + refNode = this; + } + Polymer.dom(parentNode).insertBefore(this.root, refNode); }, _removeChildren: function() { diff --git a/src/lib/template/dom-if.html b/src/lib/template/dom-if.html index dc018ba579..8952e8be5a 100644 --- a/src/lib/template/dom-if.html +++ b/src/lib/template/dom-if.html @@ -134,11 +134,18 @@ var parentNode = Polymer.dom(this).parentNode; // Guard against element being detached while render was queued if (parentNode) { - var parent = Polymer.dom(parentNode); + var refNode; + // Affordance for 2.x hybrid mode + if (parentNode.localName == this.is) { + refNode = parentNode; + parentNode = Polymer.dom(parentNode).parentNode; + } else { + refNode = this; + } if (!this._instance) { this._instance = this.stamp(); var root = this._instance.root; - parent.insertBefore(root, this); + Polymer.dom(parentNode).insertBefore(root, refNode); } else { var c$ = this._instance._children; if (c$ && c$.length) { @@ -146,7 +153,7 @@ var lastChild = Polymer.dom(this).previousSibling; if (lastChild !== c$[c$.length-1]) { for (var i=0, n; (i @@ -42,6 +42,13 @@ + + + + diff --git a/test/unit/dom-if.html b/test/unit/dom-if.html index 39dfcfbf14..3666bde095 100644 --- a/test/unit/dom-if.html +++ b/test/unit/dom-if.html @@ -71,8 +71,33 @@ + + + + +