diff --git a/lib/legacy/legacy-element-mixin.js b/lib/legacy/legacy-element-mixin.js index a6c0575c3a..76c0682dcb 100644 --- a/lib/legacy/legacy-element-mixin.js +++ b/lib/legacy/legacy-element-mixin.js @@ -122,16 +122,7 @@ export const LegacyElementMixin = dedupingMixin((base) => { * @override * @return {void} */ - created() { - // Pull all attribute values 1x if `legacyNoObservedAttributes` is set. - if (legacyNoObservedAttributes && this.hasAttributes()) { - const a = this.attributes; - for (let i=0, l=a.length; i < l; i++) { - const attr = a[i]; - this.__attributeReaction(attr.name, null, attr.value); - } - } - } + created() {} /** * Processes an attribute reaction when the `legacyNoObservedAttributes` @@ -310,6 +301,14 @@ export const LegacyElementMixin = dedupingMixin((base) => { super._initializeProperties(); this.root = /** @type {HTMLElement} */(this); this.created(); + // Pull all attribute values 1x if `legacyNoObservedAttributes` is set. + if (legacyNoObservedAttributes && this.hasAttributes()) { + const a = this.attributes; + for (let i=0, l=a.length; i < l; i++) { + const attr = a[i]; + this.__attributeReaction(attr.name, null, attr.value); + } + } // 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 diff --git a/test/unit/legacy-noattributes.html b/test/unit/legacy-noattributes.html index 1e25a99570..91b45662f3 100644 --- a/test/unit/legacy-noattributes.html +++ b/test/unit/legacy-noattributes.html @@ -66,7 +66,11 @@ camelCase: String, disabled: {type: Boolean, value: 'true'} }, + created() { + this.wasCreated = true; + }, attributeChanged(name, old, value) { + this.wasCreatedInAttributeChanged = this.wasCreated; this.attrInfo = {name, old, value}; } }); @@ -104,6 +108,10 @@ assert.equal(el.camelCase, 'camelCase'); }); + test('created called before attributeChanged', () => { + assert.isTrue(el.wasCreatedInAttributeChanged); + }); + test('attributeChanged gets expected arguments', () => { el = fixture('one-attr'); assert.deepEqual(el.attrInfo, {name: 'foo', old: null, value: 'foo'});