From e772ed0ce51f55a6c02404fa76ee4be7f9f18db9 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Mon, 15 Jul 2019 17:49:59 -0700 Subject: [PATCH] Attempt to sync host properties on every call to _showHideChildren. 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. --- lib/elements/dom-if.js | 12 ++++++------ test/unit/dom-if.html | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/elements/dom-if.js b/lib/elements/dom-if.js index 8bc21caf99..12250e4b66 100644 --- a/lib/elements/dom-if.js +++ b/lib/elements/dom-if.js @@ -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(); } } } @@ -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(); } } } diff --git a/test/unit/dom-if.html b/test/unit/dom-if.html index 4a1b5cf75d..aa115da199 100644 --- a/test/unit/dom-if.html +++ b/test/unit/dom-if.html @@ -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;