-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
useSelector returning out-of-date result #1316
Comments
This is exactly the "zombie child" problem: https://react-redux.js.org/api/hooks#stale-props-and-zombie-children It's a known deficiency of the Hooks pattern that isn't possible to solve. For these kinds of components, you should stick to |
Yep. Also, as an unrelated side note, you really shouldn't be putting mutable ES6 |
D'oh, I should have read that first. Thank you for the help! |
Sure. You might want to try out our new Redux Starter Kit package, which will warn you by default about putting non-serializable values into the store state (as well as throwing errors when you mutate). |
I will check the package out, thank you. FYI I noticed that in my sandbox example the staleness exceptions are caught by react-redux (by design) but that they aren't in my real-world application. I was able to reproduce my real-world issue by adding a wrapping component to a new sandbox and noticed something interesting: the staleness error is thrown by the selector on 7.1.0 but not on 7.1.0-alpha4. It looks like this is caused by this optimisation change. Just mentioning in case this is an opportunity to mitigate some "zombie child" issues. |
I have the same issue when running tests, using react-native 0.60.3, redux 4.0.4, react-redux 7.1.0, jest 24.0.0, react-test-renderer 16.8.6 When I dispatch two actions in a row the second one isn't changing anything in my selectors - only when I run my tests, it works fine in the app. I applied a patch to revert #1273 and now it works. |
What is the current behavior?
See this sandbox.
After deleting an entry,
useSelector
in theListHook
component returns an out-of-date result including the ID of the deleted entry. This leads to anItem
callinguseSelector
for the missing item (this is logged to the console). It looks to me like it might be because the selector is run inside an effect hook.The
ListClass
component uses the oldconnect
approach and doesn't have the same issue.What is the expected behavior?
The behaviour of the hook has caused some issues while migrating an app where selectors currently throw exceptions. I understand the hook isn't meant to be a drop-in replacement for the old approach but I'm interested to see if there is a way to avoid this while still using hooks.
Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux?
react 16.8.6
react-dom 16.8.6
react-redux 7.1.0
redux 4.0.1
Issue exists in all 7.1.0 alphas and RC.
The text was updated successfully, but these errors were encountered: