Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 434b710

Browse files
committed
Call nodeWasAdded on all the nodes in the added tree.
1 parent ce8d190 commit 434b710

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

src/ShadowRenderer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,9 @@
622622
};
623623

624624
HTMLContentElement.prototype.getDistributedNodes = function() {
625-
var renderer = this.impl.polymerShadowRenderer_;
626-
if (renderer)
627-
renderer.render();
625+
// TODO(arv): We should only rerender the dirty ancestor renderers (from
626+
// the root and down).
627+
renderAllPending();
628628
return getDistributedChildNodes(this);
629629
};
630630

src/wrappers/Node.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,11 @@
366366
* the renderer as needed.
367367
* @private
368368
*/
369-
nodeWasAdded_: function() {},
369+
nodeWasAdded_: function() {
370+
for (var child = this.firstChild; child; child = child.nextSibling) {
371+
child.nodeWasAdded_();
372+
}
373+
},
370374

371375
hasChildNodes: function() {
372376
return this.firstChild === null;

test/js/HTMLContentElement.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ suite('HTMLContentElement', function() {
5555
assertArrayEqual(content.getDistributedNodes().length, 3);
5656
});
5757

58+
test('getDistributedNodes add content deep inside tree', function() {
59+
var host = document.createElement('div');
60+
host.innerHTML = ' <a></a> <a></a> <a></a> ';
61+
var root = host.createShadowRoot();
62+
var b = document.createElement('b');
63+
var content = b.appendChild(document.createElement('content'));
64+
content.select = '*';
65+
root.appendChild(b);
66+
67+
assert.equal(content.getDistributedNodes().length, 3);
68+
assertArrayEqual(content.getDistributedNodes(), host.children);
69+
});
70+
71+
test('getDistributedNodes add content deeper inside tree', function() {
72+
var foo = document.createElement('div');
73+
var fooRoot = foo.createShadowRoot();
74+
fooRoot.innerHTML = '<div>' +
75+
' <div>item1</div> <div>item2</div> <div>item3</div> ' +
76+
'</div>';
77+
78+
var bar = fooRoot.firstChild;
79+
var barRoot = bar.createShadowRoot();
80+
barRoot.innerHTML = '<div><content></content></div>';
81+
82+
var zot = barRoot.firstChild;
83+
var zotRoot = zot.createShadowRoot();
84+
zotRoot.innerHTML = '<content select="*"></content>';
85+
var content = zotRoot.firstChild;
86+
87+
assert.equal(content.getDistributedNodes().length, 3);
88+
assertArrayEqual(content.getDistributedNodes(), fooRoot.firstChild.children);
89+
});
90+
5891
test('adding a new content element to a shadow tree', function() {
5992
var host = document.createElement('div');
6093
host.innerHTML = '<a></a><b></b>';
@@ -80,6 +113,32 @@ suite('HTMLContentElement', function() {
80113
assert.equal(unwrap(host).innerHTML, '<c></c>');
81114
});
82115

116+
test('adding a new content element to a shadow tree 2', function() {
117+
var host = document.createElement('div');
118+
host.innerHTML = '<a></a><b></b>';
119+
var a = host.firstChild;
120+
var b = host.lastChild;
121+
122+
var sr = host.createShadowRoot();
123+
sr.innerHTML = '<c></c>';
124+
var c = sr.firstChild;
125+
126+
host.offsetHeight;
127+
assert.equal(unwrap(host).innerHTML, '<c></c>');
128+
129+
var d = document.createElement('d');
130+
var content = d.appendChild(document.createElement('content'));
131+
content.select = 'b';
132+
c.appendChild(d);
133+
134+
host.offsetHeight;
135+
assert.equal(unwrap(host).innerHTML, '<c><d><b></b></d></c>');
136+
137+
c.removeChild(d);
138+
host.offsetHeight;
139+
assert.equal(unwrap(host).innerHTML, '<c></c>');
140+
});
141+
83142
test('restricting select further', function() {
84143
var host = document.createElement('div');
85144
host.innerHTML = '<a></a><b></b>';

0 commit comments

Comments
 (0)