From cd6d5d0185f72cac88b9561067abaf9a0f55174b Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Fri, 26 Jul 2019 10:24:13 -0700 Subject: [PATCH] Fix issue with defaults overriding bound values when disable-upgrade is used. --- lib/mixins/disable-upgrade-mixin.js | 11 ++++++++++ lib/mixins/element-mixin.js | 16 ++++++++++---- lib/mixins/properties-changed.js | 8 +++++++ test/unit/disable-upgrade.html | 34 ++++++++++++++++++++++++----- 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/lib/mixins/disable-upgrade-mixin.js b/lib/mixins/disable-upgrade-mixin.js index 8f5fcdfc3c..222a2b6728 100644 --- a/lib/mixins/disable-upgrade-mixin.js +++ b/lib/mixins/disable-upgrade-mixin.js @@ -99,6 +99,17 @@ export const DisableUpgradeMixin = dedupingMixin((base) => { } } + // If the element starts upgrade-disabled and a property is set for + // which an accessor exists, the default should not be applied. + // This additional check is needed because defaults are applied via + // `_initializeProperties` which is called after initial properties + // have been set when the element starts upgrade-disabled. + /** @override */ + _canApplyPropertyDefault(property) { + return super._canApplyPropertyDefault(property) && + !(this.__isUpgradeDisabled && this._isPropertyPending(property)); + } + /** * @override * @param {string} name Attribute name. diff --git a/lib/mixins/element-mixin.js b/lib/mixins/element-mixin.js index 203f6174b0..3978a269d1 100644 --- a/lib/mixins/element-mixin.js +++ b/lib/mixins/element-mixin.js @@ -562,10 +562,7 @@ export const ElementMixin = dedupingMixin(base => { } for (let p in p$) { let info = p$[p]; - // Don't set default value if there is already an own property, which - // happens when a `properties` property with default but no effects had - // a property set (e.g. bound) by its host before upgrade - if (!this.hasOwnProperty(p)) { + if (this._canApplyPropertyDefault(p)) { let value = typeof info.value == 'function' ? info.value.call(this) : info.value; @@ -580,6 +577,17 @@ export const ElementMixin = dedupingMixin(base => { } } + /** + * @param {string} property + * @returns {boolean} Returns true if the property default can be applied. + */ + // A property default can be overridden when a `properties` property with + // default but no effects had a property set (e.g. bound) by its host + // before upgrade. + _canApplyPropertyDefault(property) { + return !this.hasOwnProperty(property); + } + /** * Gather style text for a style element in the template. * diff --git a/lib/mixins/properties-changed.js b/lib/mixins/properties-changed.js index ff49a5746b..ec9eff9be8 100644 --- a/lib/mixins/properties-changed.js +++ b/lib/mixins/properties-changed.js @@ -297,6 +297,14 @@ export const PropertiesChanged = dedupingMixin( } /* eslint-enable */ + /** + * @param {string} property + * @return {boolean} Returns true if the property is pending. + */ + _isPropertyPending(property) { + return !!(this.__dataPending && this.__dataPending.hasOwnProperty(property)); + } + /** * Marks the properties as invalid, and enqueues an async * `_propertiesChanged` callback. diff --git a/test/unit/disable-upgrade.html b/test/unit/disable-upgrade.html index 6a941344ae..ff705f7e9f 100644 --- a/test/unit/disable-upgrade.html +++ b/test/unit/disable-upgrade.html @@ -30,6 +30,8 @@ }

[[prop]]

+ + default: [[default]]