From d26b003691aca1482ef9d310529ea1667f796a21 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Wed, 27 Jan 2016 12:09:57 -0800 Subject: [PATCH] Fixes #3337. When a doc fragment is added, only update the invalidation state of the insertion point list of the shadyRoot IFF it is not already invalid. This fixes an issue that was detected when an a doc fragment that did not include an insertion point was added after one that did but before distribution. --- src/lib/dom-api-shady.html | 10 +++- test/unit/polymer-dom-content.html | 74 ++++++++++++++++++++++++++---- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/lib/dom-api-shady.html b/src/lib/dom-api-shady.html index c1ed083980..b15bfac7cd 100644 --- a/src/lib/dom-api-shady.html +++ b/src/lib/dom-api-shady.html @@ -91,8 +91,14 @@ _addNode: function(node, ref_node) { var root = this.getOwnerRoot(); if (root) { - root._invalidInsertionPoints = - this._maybeAddInsertionPoint(node, this.node); + // note: we always need to see if an insertion point is added + // since this saves logical tree info; however, invalidation state + // needs + var ipAdded = this._maybeAddInsertionPoint(node, this.node); + // invalidate insertion points IFF not already invalid! + if (!root._invalidInsertionPoints) { + root._invalidInsertionPoints = ipAdded; + } this._addNodeToHost(root.host, node); } if (TreeApi.Logical.hasChildNodes(this.node)) { diff --git a/test/unit/polymer-dom-content.html b/test/unit/polymer-dom-content.html index 61b8a0a224..3b1bda2995 100644 --- a/test/unit/polymer-dom-content.html +++ b/test/unit/polymer-dom-content.html @@ -168,6 +168,24 @@ + + + + + @@ -1647,7 +1665,7 @@ assert.equal(c1.parentNode, el.$.container1); assert.equal(c2.parentNode, el.$.container1); } - el.foo = !el.foo; + el.foo = false; el.$.foo.render(); el.$.notFoo.render(); Polymer.dom.flush(); @@ -1655,7 +1673,7 @@ assert.equal(c1.parentNode, el.$.container2); assert.equal(c2.parentNode, el.$.container2); } - el.foo = !el.foo; + el.foo = true; el.$.foo.render(); el.$.notFoo.render(); Polymer.dom.flush(); @@ -1663,7 +1681,7 @@ assert.equal(c1.parentNode, el.$.container1); assert.equal(c2.parentNode, el.$.container1); } - el.foo = !el.foo; + el.foo = false; el.$.foo.render(); el.$.notFoo.render(); Polymer.dom.flush(); @@ -1671,7 +1689,7 @@ assert.equal(c1.parentNode, el.$.container2); assert.equal(c2.parentNode, el.$.container2); } - el.foo = !el.foo; + el.foo = true; el.$.foo.render(); el.$.notFoo.render(); Polymer.dom.flush(); @@ -1682,6 +1700,46 @@ document.body.removeChild(el); }); + test('x-dynamic-content-and-dynamic-no-content', function() { + var el = document.createElement('x-dynamic-content-and-dynamic-no-content'); + document.body.appendChild(el); + var c1 = document.createElement('div'); + c1.id = 'one'; + Polymer.dom(el).appendChild(c1); + Polymer.dom.flush(); + assert.equal(Polymer.dom(el).querySelector('#one'), c1); + assert.notOk(Polymer.dom(el.root).querySelector('#static')); + assert.notOk(Polymer.dom(el.root).querySelector('content')); + el.$.contentIf.if = true; + el.$.staticIf.if = true; + Polymer.dom.flush(); + assert.ok(Polymer.dom(el.root).querySelector('#static')); + var ip = Polymer.dom(el.root).querySelector('content'); + assert.ok(ip); + assert.equal(Polymer.dom(ip).getDistributedNodes()[0], c1); + if (el.shadyRoot) { + assert.ok(el.$.container.querySelector('#one')); + } + el.$.contentIf.if = false; + el.$.staticIf.if = false; + Polymer.dom.flush(); + assert.equal(Polymer.dom(el).querySelector('#one'), c1); + assert.notOk(Polymer.dom(el.root).querySelector('#static')); + assert.notOk(Polymer.dom(el.root).querySelector('content')); + el.$.contentIf.if = true; + el.$.staticIf.if = true; + Polymer.dom.flush(); + assert.ok(Polymer.dom(el.root).querySelector('#static')); + var ip = Polymer.dom(el.root).querySelector('content'); + assert.ok(ip); + assert.equal(Polymer.dom(ip).getDistributedNodes()[0], c1); + if (el.shadyRoot) { + assert.ok(el.$.container.querySelector('#one')); + } + document.body.removeChild(el); + + }); + });