Skip to content

Commit

Permalink
Attempt to sync host properties on every call to _showHideChildren.
Browse files Browse the repository at this point in the history
Fixes an issue where a dom-if that is toggled synchronously true-false-true could fail to sync properties invalidated while false, since the hidden state is only checked at render timing, and the newly added dirty-check could fail if the hidden state has been changed back to its initial value.
  • Loading branch information
kevinpschaaf committed Jul 16, 2019
1 parent c563d5a commit e772ed0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/elements/dom-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ class DomIfFast extends DomIfBase {
if (this.__instance && Boolean(this.__instance.__hidden) !== hidden) {
this.__instance.__hidden = hidden;
showHideChildren(hidden, this.__instance.templateInfo.childNodes);
if (!hidden) {
this.__syncHostProperties();
}
}
if (!hidden) {
this.__syncHostProperties();
}
}
}
Expand Down Expand Up @@ -615,9 +615,9 @@ class DomIfLegacy extends DomIfBase {
if (this.__instance && Boolean(this.__instance.__hidden) !== hidden) {
this.__instance.__hidden = hidden;
this.__instance._showHideChildren(hidden);
if (!hidden) {
this.__syncHostProperties();
}
}
if (!hidden) {
this.__syncHostProperties();
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/unit/dom-if.html
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,21 @@
document.body.removeChild(el);
});

test.only('host properties in sync toggling true-false-true synchronously', function() {
let el = document.createElement('x-guard-separate-props');
el.restamp = restamp;
document.body.appendChild(el);
el.a = 'initial';
el.b = true;
flush();
assert.equal(el.shadowRoot.textContent.trim(), 'initial');
el.setProperties({b: false, a: 'changed'});
el.b = true;
flush();
assert.equal(el.shadowRoot.textContent.trim(), 'changed');
document.body.removeChild(el);
});

test('host paths in sync when changed while false', function() {
let el = document.createElement('x-guard-separate-paths');
el.restamp = restamp;
Expand Down

0 comments on commit e772ed0

Please sign in to comment.