You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[reactive-element] addInitializer adds initializer to superclass #3373
While looking #3296 a bit more in depth, I realize that the culprit is not @lit-labs/context but ReactiveElement.addInitializer, which will add intializers to the superclass if it already contains its own initializers.
Initializers are stored per-constructor. Adding an initializer to a subclass does not add it to a superclass. Since initializers are run in constructors, initializers will run in order of the class hierarchy, starting with superclasses and progressing to the instance's class.
This is not what happens as addInitializer only checks if this._initializer exists on the Class prototype chain. In case a superclass already has one, it will be added to it (the superclass). We should have a hasOwnProperty check there.
/* * Initializers are stored per-constructor. Adding an initializer to a * subclass does not add it to a superclass. Since initializers are run in * constructors, initializers will run in order of the class hierarchy, * starting with superclasses and progressing to the instance's class. * * @nocollapse */staticaddInitializer(initializer: Initializer){this._initializers??=[];this._initializers.push(initializer);}
changed the title [-]ReactiveElement.addInitializer adds initializer to superclass[/-][+][reactive-element] addInitializer adds initializer to superclass[/+]on Oct 18, 2022
Just a quick note, this should be fixed in the finalize step where we handle similar behavior for properties and styles. The superclass initializers should be copied into a set of initializers owned by (and not shared with!) the superclass.
Activity
[-]ReactiveElement.addInitializer adds initializer to superclass[/-][+][reactive-element] addInitializer adds initializer to superclass[/+]justinfagnani commentedon Oct 18, 2022
Thanks for investigating this and for the repro @christophe-g !
We can prioritize a fix for this, or you could contribute it if you would like to. The biggest requirement would be a good test.
sorvell commentedon Oct 18, 2022
Just a quick note, this should be fixed in the
finalizestep where we handle similar behavior for properties and styles. The superclass initializers should be copied into a set of initializers owned by (and not shared with!) the superclass.christophe-g commentedon Oct 18, 2022
@justinfagnani - honestly, while I'd like to contribute, I am already pretty stretched over a couple of important deadlines on my end ; )
The fix should be pretty straighforward and the lit team shall be in better position to efficiently tackle this (esp. on the good test requirement).