diff --git a/lib/legacy/class.js b/lib/legacy/class.js index 5e7062c764..9bfd066bf1 100644 --- a/lib/legacy/class.js +++ b/lib/legacy/class.js @@ -238,6 +238,24 @@ function GenerateClassFromInfo(info, Base, behaviors) { return observedAttributesGetter.call(this).concat(DISABLED_ATTR); } + // Prevent element from initializing properties when it's upgrade disabled. + /** @override */ + _initializeProperties() { + if (!this.hasAttribute(DISABLED_ATTR)) { + super._initializeProperties(); + } else { + this.__isUpgradeDisabled = true; + } + } + + // Prevent element from enabling properties when it's upgrade disabled. + /** @override */ + _enableProperties() { + if (!this.__isUpgradeDisabled) { + super._enableProperties(); + } + } + /** * @override * @param {string} name Attribute name. @@ -248,8 +266,14 @@ function GenerateClassFromInfo(info, Base, behaviors) { */ attributeChangedCallback(name, old, value, namespace) { if (name == DISABLED_ATTR) { - if (!this.__dataEnabled && value == null && this.isConnected) { - super.connectedCallback(); + // When disable-upgrade is removed, intialize properties and + // provoke connectedCallback if the element is already connected. + if (!this.__dataEnabled && value == null) { + super._initializeProperties(); + this.__isUpgradeDisabled = false; + if (this.isConnected) { + super.connectedCallback(); + } } } else { super.attributeChangedCallback( @@ -257,39 +281,18 @@ function GenerateClassFromInfo(info, Base, behaviors) { } } - - // prevent user code in connected from running + // Prevent element from connecting when it's upgrade disabled. /** @override */ connectedCallback() { - if (this.__dataEnabled || !this.hasAttribute(DISABLED_ATTR)) { + if (!this.__isUpgradeDisabled) { super.connectedCallback(); } } - _initializeProperties() { - if (!this.hasAttribute(DISABLED_ATTR)) { - super._initializeProperties(); - } else { - this.__wasDisabled = true; - } - } - - // prevent element from turning on properties - /** @override */ - _enableProperties() { - if (this.__wasDisabled) { - this.__wasDisabled = false; - super._initializeProperties(); - } - if (!this.hasAttribute(DISABLED_ATTR)) { - super._enableProperties(); - } - } - - // only go if "enabled" + // Prevent element from disconnecting when it's upgrade disabled. /** @override */ disconnectedCallback() { - if (this.__dataEnabled) { + if (!this.__isUpgradeDisabled) { super.disconnectedCallback(); } }