diff --git a/lib/legacy/legacy-element-mixin.html b/lib/legacy/legacy-element-mixin.html
index 3ce281c363..0ecc44ee8a 100644
--- a/lib/legacy/legacy-element-mixin.html
+++ b/lib/legacy/legacy-element-mixin.html
@@ -73,14 +73,12 @@
constructor() {
super();
- this.root = this;
/** @type {boolean} */
this.isAttached;
/** @type {WeakMap>} */
this.__boundListeners;
/** @type {Object} */
this._debouncers;
- this.created();
// Ensure listeners are applied immediately so that they are
// added before declarative event listeners. This allows an element to
// decorate itself via an event prior to any declarative listeners
@@ -166,6 +164,8 @@
this._registered();
}
super._initializeProperties();
+ this.root = this;
+ this.created();
}
/**
diff --git a/lib/mixins/disable-upgrade-mixin.html b/lib/mixins/disable-upgrade-mixin.html
index 17af982799..a430995dce 100644
--- a/lib/mixins/disable-upgrade-mixin.html
+++ b/lib/mixins/disable-upgrade-mixin.html
@@ -55,20 +55,26 @@
}
}
- __shouldEnable() {
- return this.__dataEnabled || !this.hasAttribute(DISABLED_ATTR);
- }
+ /*
+ NOTE: cannot gate on attribute because this is called before
+ attributes are delivered. Therefore, we stub this out and
+ call `super._initializeProperties()` manually.
+ */
+ _initializeProperties() {}
// prevent user code in connected from running
connectedCallback() {
- if (this.__shouldEnable()) {
+ if (this.__dataEnabled || !this.hasAttribute(DISABLED_ATTR)) {
super.connectedCallback();
}
}
// prevent element from turning on properties
_enableProperties() {
- if (this.__shouldEnable()) {
+ if (!this.hasAttribute(DISABLED_ATTR)) {
+ if (!this.__dataEnabled) {
+ super._initializeProperties();
+ }
super._enableProperties();
}
}
diff --git a/test/unit/disable-upgrade.html b/test/unit/disable-upgrade.html
index fd2b6cb1f7..533476e81b 100644
--- a/test/unit/disable-upgrade.html
+++ b/test/unit/disable-upgrade.html
@@ -57,6 +57,65 @@ [[prop]]
+
+
+
+ [[prop]]
+
+
+
+
+
+
@@ -84,6 +143,33 @@ [[prop]]
+
+
+
+ Disabled
+ Disabled
+ Disabled
+ Disabled
+ Disabled
+
+
+
+
+
+
+
+
+ suite('disable-upgrade-legacy', function() {
+ let el;
+
+ setup(() => {
+ el = document.createElement('my-element-legacy');
+ document.body.appendChild(el);
+ });
+ teardown(function() {
+ document.body.removeChild(el);
+ });
+
+ test('elements call `registered` as expected with `disable-upgrade`', function() {
+ assert.notOk(el.$.disabledRegEl.hasRegistered);
+ assert.notOk(el.$.disabledRegBoundEl.hasRegistered);
+ el.enable();
+ assert.ok(el.$.disabledRegEl.hasRegistered);
+ assert.ok(el.$.disabledRegBoundEl.hasRegistered);
+ });
+
+
+ test('elements upgrade as expected with and without `disable-upgrade`', function() {
+ assert.ok(el.$.enabledEl.hasCreated);
+ assert.ok(el.$.enabledEl.enabled);
+ assert.ok(el.$.enabledEl.$.element);
+ assert.equal(el.$.enabledEl.$.element.textContent, 'enabled!');
+ assert.notOk(el.$.disabledEl.hasCreated);
+ assert.notOk(el.$.disabledEl.enabled);
+ assert.notOk(el.$.disabledEl.$);
+ assert.notOk(el.$.disabledBoundEl.hasCreated);
+ assert.notOk(el.$.disabledBoundEl.enabled);
+ assert.notOk(el.$.disabledBoundEl.$);
+ });
+
+ test('elements upgrade when `disable-upgrade` removed', function() {
+ assert.notOk(el.$.disabledEl.hasCreated);
+ assert.notOk(el.$.disabledEl.enabled);
+ assert.notOk(el.$.disabledEl.$);
+ assert.notOk(el.$.disabledBoundEl.hasCreated);
+ assert.notOk(el.$.disabledBoundEl.enabled);
+ assert.notOk(el.$.disabledBoundEl.$);
+ el.enable();
+ assert.ok(el.$.disabledEl.hasCreated);
+ assert.ok(el.$.disabledEl.enabled);
+ assert.ok(el.$.disabledEl.$.element);
+ assert.equal(el.$.disabledEl.$.element.textContent, 'enabled!');
+ assert.ok(el.$.disabledBoundEl.hasCreated);
+ assert.ok(el.$.disabledBoundEl.enabled);
+ assert.ok(el.$.disabledBoundEl.$.element);
+ assert.equal(el.$.disabledBoundEl.$.element.textContent, 'enabled!');
+ });
+
+
+ });
+