yewstack / yew

Rust / Wasm framework for creating reliable and efficient web applications
https://yew.rs
Apache License 2.0
30.23k stars 1.41k forks source link

Issue with change detection? #3643

Closed mh84 closed 3 months ago

mh84 commented 3 months ago

Problem I've encountered some strange behavior i'm assuming a bug in yew where elements after updating context not having the correct content, i assume there is some problem with change detection. In my scenario you have a page where you are able to navigate (blue action button "A") or filter the current view (yellow filter button "F"). After filtering, you can go back (blue button "B"). Actually, after filtering using "F" and navigating back using "B" you will see Buttons action "A" and back "b" instead of filter "F".

Steps To Reproduce Reproduction

Expected behavior When using "F" to filter and using "B" to go back after, you see action "A" and filter "F" again.

Screenshots Initial: grafik Click "F": grafik Click "B": grafik

Environment:

Questionnaire

mh84 commented 3 months ago

I did some further research and found out that the behaviour changed in 0.19 (and i followed this downwards to 0.14.0), where the behavior changed but was also wrong: grafik

mh84 commented 3 months ago

One last discovery: when changing the button to function component, it is working as intended.

WorldSEnder commented 3 months ago

Not a bug. The renderer re-uses an existing instance of your <Button /> component with updated properties. Yet, you "precompute" its icon and class (and onclick) only in the component's create. This leads to a wrong and outdated icon being rendered for a component has correctly updated props. Move that logic from create to the view to fix it.

mh84 commented 3 months ago

Alright, i wasn't aware that this would be considered as property change, thanks for explaining this.