Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observers called multiple times in inheritance chain #5067

Closed
LarsDenBakker opened this issue Jan 27, 2018 · 7 comments
Closed

Observers called multiple times in inheritance chain #5067

LarsDenBakker opened this issue Jan 27, 2018 · 7 comments

Comments

@LarsDenBakker
Copy link
Contributor

LarsDenBakker commented Jan 27, 2018

Description

I have two classes, base-element defines an observer and my-element extends base-element with no own properties. Both are placed in the dom with the property set. The observer of just base-element is called once. The observer of my-element (which was inherited from base-element) is called twice.

http://jsbin.com/wimozeravo/1/edit?html,console,output

Adding an empty properties set to my-element makes the observer fire only once:

http://jsbin.com/giniqeweco/1/edit?html,console,output

It seems that when a class in an inheritance chain defines a property observer, for each class in the inheritance chain that does not define a properties getter, the property observer is called once extra.

This can be illustrated with mixins (which are just classes).

Here there are two mixins and a class. The first mixin defines an observer and the others don't define any properties. The observer is fired thrice:

http://jsbin.com/hilularuce/1/edit?html,console,output

With empty properties it's fired once:

http://jsbin.com/domakayufu/1/edit?html,console,output

@LarsDenBakker
Copy link
Contributor Author

I use this pattern a lot in my codebase, and I was thinking how this could possibly not have caused any issues for me before.

Then I realized that 2.4 just got released yesterday. After downgrading this issue no longer there, so it seems that this is a regression in the new PropertiesMixin. :(

I couldn't get the jsbin pointing to the 2.3.1 working.

@web-padawan
Copy link
Contributor

I can confirm the issue, this is affecting us as well, especially by breaking observers used to set and then check some flags. See this build for vaadin-combo-box and the observer code here.

I quickly investigated and was able to reproduce it locally: adding console.log inside of the single property observer indicates that it does fire twice for the same old and new values.

@TimvdLippe
Copy link
Contributor

Thanks for reporting! Did quite some digging, but I was able to figure it out. Fix up at #5068

@LarsDenBakker
Copy link
Contributor Author

Thanks!

@LarsDenBakker
Copy link
Contributor Author

Any updates on this? 2.4 is announced now, and this will affect most peoples codebases.

@TimvdLippe
Copy link
Contributor

@LarsDenBakker #5068 will be reviewed by @kevinpschaaf and @sorvell and hopefully merged today 🎉

@LarsDenBakker
Copy link
Contributor Author

When can we expect a 2.4.1? Checking so that I can plan accordingly for the release of our app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants