Skip to content

Commit 5e1a8b6

Browse files
committed
Ensure parent is linked to child templateInfo. Fixes fastDomIf unstopping issue.
1 parent 590f74a commit 5e1a8b6

File tree

3 files changed

+88
-12
lines changed

3 files changed

+88
-12
lines changed

lib/mixins/property-effects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
27562756
// once).
27572757
const parent = template._parentTemplateInfo || this.__templateInfo;
27582758
const previous = parent.lastChild;
2759+
templateInfo.parent = parent;
27592760
parent.lastChild = templateInfo;
27602761
templateInfo.previousSibling = previous;
27612762
if (previous) {

test/unit/dom-if-elements.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,15 @@ Polymer({
126126
<x-foo prop="{{prop1}}"></x-foo>
127127
<template is="dom-if" id="if-2" if="{{shouldStamp2}}">
128128
<x-foo prop="{{prop2}}"></x-foo>
129-
<template is="dom-if" id="if-3" if="{{shouldStamp3}}">
129+
<template is="dom-if" id="if-3" if="{{shouldStamp3}}" restamp>
130130
<x-foo prop="{{prop3}}"></x-foo>
131131
</template>
132+
<template is="dom-if" id="if-4" if="{{shouldStamp4}}" restamp>
133+
<x-foo prop="{{prop4}}"></x-foo>
134+
</template>
135+
<template is="dom-if" id="if-5" if="{{shouldStamp5}}" restamp>
136+
<x-foo prop="{{prop5}}"></x-foo>
137+
</template>
132138
</template>
133139
</template>
134140
`,
@@ -145,6 +151,12 @@ Polymer({
145151
prop3: {
146152
value: 'prop3'
147153
},
154+
prop4: {
155+
value: 'prop4'
156+
},
157+
prop5: {
158+
value: 'prop5'
159+
},
148160
item: {
149161
value: function() { return {prop: 'outerItem'}; }
150162
}

test/unit/dom-if.html

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,54 +191,117 @@
191191
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
192192
});
193193

194-
test('hide 3', function() {
195-
individual.shouldStamp3 = false;
194+
test('show 4', function() {
195+
individual.shouldStamp4 = true;
196+
individual.render();
197+
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
198+
assert.equal(stamped.length, 4, 'total stamped count incorrect');
199+
assert.equal(stamped[0].prop, 'prop1');
200+
assert.equal(stamped[1].prop, 'prop2');
201+
assert.equal(stamped[2].prop, 'prop3');
202+
assert.equal(stamped[3].prop, 'prop4');
203+
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
204+
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
205+
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
206+
assert.equal(getComputedStyle(stamped[3]).display, 'inline', 'stamped 4 display wrong');
207+
});
208+
209+
test('remove 4', function() {
210+
individual.shouldStamp4 = false;
211+
individual.render();
212+
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
213+
assert.equal(stamped.length, 3, 'total stamped count incorrect');
214+
assert.equal(stamped[0].prop, 'prop1');
215+
assert.equal(stamped[1].prop, 'prop2');
216+
assert.equal(stamped[2].prop, 'prop3');
217+
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
218+
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
219+
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
220+
});
221+
222+
test('show 5', function() {
223+
individual.shouldStamp5 = true;
224+
individual.render();
225+
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
226+
assert.equal(stamped.length, 4, 'total stamped count incorrect');
227+
assert.equal(stamped[0].prop, 'prop1');
228+
assert.equal(stamped[1].prop, 'prop2');
229+
assert.equal(stamped[2].prop, 'prop3');
230+
assert.equal(stamped[3].prop, 'prop5');
231+
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
232+
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
233+
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
234+
assert.equal(getComputedStyle(stamped[3]).display, 'inline', 'stamped 5 display wrong');
235+
});
236+
237+
test('update 5', function() {
238+
individual.prop5 = 'prop5*';
239+
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
240+
assert.equal(stamped.length, 4, 'total stamped count incorrect');
241+
assert.equal(stamped[0].prop, 'prop1');
242+
assert.equal(stamped[1].prop, 'prop2');
243+
assert.equal(stamped[2].prop, 'prop3');
244+
assert.equal(stamped[3].prop, 'prop5*');
245+
});
246+
247+
test('remove 5', function() {
248+
individual.shouldStamp5 = false;
196249
individual.render();
197250
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
198251
assert.equal(stamped.length, 3, 'total stamped count incorrect');
252+
assert.equal(stamped[0].prop, 'prop1');
253+
assert.equal(stamped[1].prop, 'prop2');
254+
assert.equal(stamped[2].prop, 'prop3');
255+
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
256+
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
257+
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
258+
});
259+
260+
test('remove 3', function() {
261+
individual.shouldStamp3 = false;
262+
individual.render();
263+
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
264+
assert.equal(stamped.length, 2, 'total stamped count incorrect');
265+
assert.equal(stamped[0].prop, 'prop1');
266+
assert.equal(stamped[1].prop, 'prop2');
199267
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
200268
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
201-
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
202269
});
203270

204271
test('hide 2', function() {
205272
individual.shouldStamp2 = false;
206273
individual.render();
207274
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
208-
assert.equal(stamped.length, 3, 'total stamped count incorrect');
275+
assert.equal(stamped.length, 2, 'total stamped count incorrect');
209276
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
210277
assert.equal(getComputedStyle(stamped[1]).display, 'none', 'stamped 2 display wrong');
211-
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
212278
});
213279

214280
test('hide 1', function() {
215281
individual.shouldStamp1 = false;
216282
individual.render();
217283
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
218-
assert.equal(stamped.length, 3, 'total stamped count incorrect');
284+
assert.equal(stamped.length, 2, 'total stamped count incorrect');
219285
assert.equal(getComputedStyle(stamped[0]).display, 'none', 'stamped 1 display wrong');
220286
assert.equal(getComputedStyle(stamped[1]).display, 'none', 'stamped 2 display wrong');
221-
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
222287
});
223288

224289
test('show 1', function() {
225290
individual.shouldStamp1 = true;
226291
individual.render();
227292
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
228-
assert.equal(stamped.length, 3, 'total stamped count incorrect');
293+
assert.equal(stamped.length, 2, 'total stamped count incorrect');
229294
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
230295
assert.equal(getComputedStyle(stamped[1]).display, 'none', 'stamped 2 display wrong');
231-
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
232296
});
233297

234298
test('show 2', function() {
235299
individual.shouldStamp2 = true;
236300
individual.render();
237301
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
238-
assert.equal(stamped.length, 3, 'total stamped count incorrect');
302+
assert.equal(stamped.length, 2, 'total stamped count incorrect');
239303
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
240304
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
241-
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
242305
});
243306

244307
test('show 3', function() {

0 commit comments

Comments
 (0)