Issue with change detection?
mh84 opened this issue · comments
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:
Click "F":
Click "B":
Environment:
- Yew version: 0.21
- Rust version: rustc 1.79.0-nightly (c9f8f3438 2024-03-27)
- Build tool, if relevant: Trunk (i guess it doesn't matter)
- OS, if relevant: Linux (i guess it doesn't matter)
- Browser and version, if relevant: Chromium, Firefox
Questionnaire
- I'm interested in fixing this myself but don't know where to start
- I would like to fix and I have a solution
- I don't have time to fix this right now, but maybe later
One last discovery: when changing the button to function component, it is working as intended.
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.
Alright, i wasn't aware that this would be considered as property change, thanks for explaining this.