Skip to content

Commit d26b003

Browse files
author
Steven Orvell
committed
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.
1 parent 3ffc3e2 commit d26b003

2 files changed

Lines changed: 74 additions & 10 deletions

File tree

‎src/lib/dom-api-shady.html‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@
9191
_addNode: function(node, ref_node) {
9292
var root = this.getOwnerRoot();
9393
if (root) {
94-
root._invalidInsertionPoints =
95-
this._maybeAddInsertionPoint(node, this.node);
94+
// note: we always need to see if an insertion point is added
95+
// since this saves logical tree info; however, invalidation state
96+
// needs
97+
var ipAdded = this._maybeAddInsertionPoint(node, this.node);
98+
// invalidate insertion points IFF not already invalid!
99+
if (!root._invalidInsertionPoints) {
100+
root._invalidInsertionPoints = ipAdded;
101+
}
96102
this._addNodeToHost(root.host, node);
97103
}
98104
if (TreeApi.Logical.hasChildNodes(this.node)) {

‎test/unit/polymer-dom-content.html‎

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@
168168
</script>
169169
</dom-module>
170170

171+
<dom-module id="x-dynamic-content-and-dynamic-no-content">
172+
<template>
173+
<div id="container">
174+
<template is="dom-if" id="staticIf" restamp>
175+
<div id="static">satatic</div>
176+
</template>
177+
<template is="dom-if" id="contentIf" restamp>
178+
<content select="*"></content>
179+
</template>
180+
</div>
181+
</template>
182+
<script>
183+
HTMLImports.whenReady(function() {
184+
Polymer({is: 'x-dynamic-content-and-dynamic-no-content'});
185+
});
186+
</script>
187+
</dom-module>
188+
171189
<dom-module id="x-multi-dist">
172190
<template>
173191
<x-dist id="dist1"><content id="content1"></content></x-dist>
@@ -204,15 +222,15 @@
204222
<div id="container1">
205223
<template id="foo" is="dom-if" if="{{foo}}" restamp>
206224
<span>foo</span>
207-
<content select="#one"></content>
208-
<content select="#two"></content>
225+
<content id="1.1" select="#one"></content>
226+
<content id="1.2" select="#two"></content>
209227
</template>
210228
</div>
211229
<div id="container2">
212230
<template id="notFoo" is="dom-if" if="{{!foo}}" restamp>
213231
<span>Not foo</span>
214-
<content select="#one"></content>
215-
<content select="#two"></content>
232+
<content id="2.1" select="#one"></content>
233+
<content id="2.2" select="#two"></content>
216234
</template>
217235
</div>
218236
</template>
@@ -1647,31 +1665,31 @@
16471665
assert.equal(c1.parentNode, el.$.container1);
16481666
assert.equal(c2.parentNode, el.$.container1);
16491667
}
1650-
el.foo = !el.foo;
1668+
el.foo = false;
16511669
el.$.foo.render();
16521670
el.$.notFoo.render();
16531671
Polymer.dom.flush();
16541672
if (usingShady) {
16551673
assert.equal(c1.parentNode, el.$.container2);
16561674
assert.equal(c2.parentNode, el.$.container2);
16571675
}
1658-
el.foo = !el.foo;
1676+
el.foo = true;
16591677
el.$.foo.render();
16601678
el.$.notFoo.render();
16611679
Polymer.dom.flush();
16621680
if (usingShady) {
16631681
assert.equal(c1.parentNode, el.$.container1);
16641682
assert.equal(c2.parentNode, el.$.container1);
16651683
}
1666-
el.foo = !el.foo;
1684+
el.foo = false;
16671685
el.$.foo.render();
16681686
el.$.notFoo.render();
16691687
Polymer.dom.flush();
16701688
if (usingShady) {
16711689
assert.equal(c1.parentNode, el.$.container2);
16721690
assert.equal(c2.parentNode, el.$.container2);
16731691
}
1674-
el.foo = !el.foo;
1692+
el.foo = true;
16751693
el.$.foo.render();
16761694
el.$.notFoo.render();
16771695
Polymer.dom.flush();
@@ -1682,6 +1700,46 @@
16821700
document.body.removeChild(el);
16831701
});
16841702

1703+
test('x-dynamic-content-and-dynamic-no-content', function() {
1704+
var el = document.createElement('x-dynamic-content-and-dynamic-no-content');
1705+
document.body.appendChild(el);
1706+
var c1 = document.createElement('div');
1707+
c1.id = 'one';
1708+
Polymer.dom(el).appendChild(c1);
1709+
Polymer.dom.flush();
1710+
assert.equal(Polymer.dom(el).querySelector('#one'), c1);
1711+
assert.notOk(Polymer.dom(el.root).querySelector('#static'));
1712+
assert.notOk(Polymer.dom(el.root).querySelector('content'));
1713+
el.$.contentIf.if = true;
1714+
el.$.staticIf.if = true;
1715+
Polymer.dom.flush();
1716+
assert.ok(Polymer.dom(el.root).querySelector('#static'));
1717+
var ip = Polymer.dom(el.root).querySelector('content');
1718+
assert.ok(ip);
1719+
assert.equal(Polymer.dom(ip).getDistributedNodes()[0], c1);
1720+
if (el.shadyRoot) {
1721+
assert.ok(el.$.container.querySelector('#one'));
1722+
}
1723+
el.$.contentIf.if = false;
1724+
el.$.staticIf.if = false;
1725+
Polymer.dom.flush();
1726+
assert.equal(Polymer.dom(el).querySelector('#one'), c1);
1727+
assert.notOk(Polymer.dom(el.root).querySelector('#static'));
1728+
assert.notOk(Polymer.dom(el.root).querySelector('content'));
1729+
el.$.contentIf.if = true;
1730+
el.$.staticIf.if = true;
1731+
Polymer.dom.flush();
1732+
assert.ok(Polymer.dom(el.root).querySelector('#static'));
1733+
var ip = Polymer.dom(el.root).querySelector('content');
1734+
assert.ok(ip);
1735+
assert.equal(Polymer.dom(ip).getDistributedNodes()[0], c1);
1736+
if (el.shadyRoot) {
1737+
assert.ok(el.$.container.querySelector('#one'));
1738+
}
1739+
document.body.removeChild(el);
1740+
1741+
});
1742+
16851743
});
16861744

16871745
</script>

0 commit comments

Comments
 (0)