Skip to content

Commit

Permalink
Ensure parent is linked to child templateInfo. Fixes fastDomIf unstop…
Browse files Browse the repository at this point in the history
…ping issue.
  • Loading branch information
kevinpschaaf committed Aug 29, 2019
1 parent 590f74a commit 5e1a8b6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
// once).
const parent = template._parentTemplateInfo || this.__templateInfo;
const previous = parent.lastChild;
templateInfo.parent = parent;
parent.lastChild = templateInfo;
templateInfo.previousSibling = previous;
if (previous) {
Expand Down
14 changes: 13 additions & 1 deletion test/unit/dom-if-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,15 @@ Polymer({
<x-foo prop="{{prop1}}"></x-foo>
<template is="dom-if" id="if-2" if="{{shouldStamp2}}">
<x-foo prop="{{prop2}}"></x-foo>
<template is="dom-if" id="if-3" if="{{shouldStamp3}}">
<template is="dom-if" id="if-3" if="{{shouldStamp3}}" restamp>
<x-foo prop="{{prop3}}"></x-foo>
</template>
<template is="dom-if" id="if-4" if="{{shouldStamp4}}" restamp>
<x-foo prop="{{prop4}}"></x-foo>
</template>
<template is="dom-if" id="if-5" if="{{shouldStamp5}}" restamp>
<x-foo prop="{{prop5}}"></x-foo>
</template>
</template>
</template>
`,
Expand All @@ -145,6 +151,12 @@ Polymer({
prop3: {
value: 'prop3'
},
prop4: {
value: 'prop4'
},
prop5: {
value: 'prop5'
},
item: {
value: function() { return {prop: 'outerItem'}; }
}
Expand Down
85 changes: 74 additions & 11 deletions test/unit/dom-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,54 +191,117 @@
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
});

test('hide 3', function() {
individual.shouldStamp3 = false;
test('show 4', function() {
individual.shouldStamp4 = true;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 4, 'total stamped count incorrect');
assert.equal(stamped[0].prop, 'prop1');
assert.equal(stamped[1].prop, 'prop2');
assert.equal(stamped[2].prop, 'prop3');
assert.equal(stamped[3].prop, 'prop4');
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
assert.equal(getComputedStyle(stamped[3]).display, 'inline', 'stamped 4 display wrong');
});

test('remove 4', function() {
individual.shouldStamp4 = false;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
assert.equal(stamped[0].prop, 'prop1');
assert.equal(stamped[1].prop, 'prop2');
assert.equal(stamped[2].prop, 'prop3');
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
});

test('show 5', function() {
individual.shouldStamp5 = true;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 4, 'total stamped count incorrect');
assert.equal(stamped[0].prop, 'prop1');
assert.equal(stamped[1].prop, 'prop2');
assert.equal(stamped[2].prop, 'prop3');
assert.equal(stamped[3].prop, 'prop5');
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
assert.equal(getComputedStyle(stamped[3]).display, 'inline', 'stamped 5 display wrong');
});

test('update 5', function() {
individual.prop5 = 'prop5*';
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 4, 'total stamped count incorrect');
assert.equal(stamped[0].prop, 'prop1');
assert.equal(stamped[1].prop, 'prop2');
assert.equal(stamped[2].prop, 'prop3');
assert.equal(stamped[3].prop, 'prop5*');
});

test('remove 5', function() {
individual.shouldStamp5 = false;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
assert.equal(stamped[0].prop, 'prop1');
assert.equal(stamped[1].prop, 'prop2');
assert.equal(stamped[2].prop, 'prop3');
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'inline', 'stamped 3 display wrong');
});

test('remove 3', function() {
individual.shouldStamp3 = false;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 2, 'total stamped count incorrect');
assert.equal(stamped[0].prop, 'prop1');
assert.equal(stamped[1].prop, 'prop2');
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
});

test('hide 2', function() {
individual.shouldStamp2 = false;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
assert.equal(stamped.length, 2, 'total stamped count incorrect');
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'none', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
});

test('hide 1', function() {
individual.shouldStamp1 = false;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
assert.equal(stamped.length, 2, 'total stamped count incorrect');
assert.equal(getComputedStyle(stamped[0]).display, 'none', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'none', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
});

test('show 1', function() {
individual.shouldStamp1 = true;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
assert.equal(stamped.length, 2, 'total stamped count incorrect');
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'none', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
});

test('show 2', function() {
individual.shouldStamp2 = true;
individual.render();
let stamped = individual.shadowRoot.querySelectorAll('*:not(template):not(dom-if):not(span)');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
assert.equal(stamped.length, 2, 'total stamped count incorrect');
assert.equal(getComputedStyle(stamped[0]).display, 'inline', 'stamped 1 display wrong');
assert.equal(getComputedStyle(stamped[1]).display, 'inline', 'stamped 2 display wrong');
assert.equal(getComputedStyle(stamped[2]).display, 'none', 'stamped 3 display wrong');
});

test('show 3', function() {
Expand Down

0 comments on commit 5e1a8b6

Please sign in to comment.