Skip to content
New issue

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

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

Already on GitHub? # to your account

Stale values in useSelector closure #2060

Open
1 task done
zimmru opened this issue Aug 11, 2023 · 0 comments
Open
1 task done

Stale values in useSelector closure #2060

zimmru opened this issue Aug 11, 2023 · 0 comments

Comments

@zimmru
Copy link

zimmru commented Aug 11, 2023

What version of React, ReactDOM/React Native, Redux, and React Redux are you using?

  • React: 18.2
  • React Redux: 8.x (I'm able to reproduce this issue in all versions I've tried: 8.0.0, 8.0.5, and 8.1.2)

What is the current behavior?

I'm updating a project from react-redux 7.x to 8.x, and I think I'm running into a bug. I'm seeing a call to useSelector with stale captured values. Here's a simplified project that demonstrates the issue: https://codesandbox.io/s/react-redux-8-closure-w8zqf4?file=/src/App.js

When the "Dispatch" button is clicked, the first useSelector is called 5 times. All calls are expected except the third. The additional call would be fine except the captured variable now has reverted back to its original value for that call--the second time it was called, it had already been updated. Note: if you open the console, you'll see a message about "captured stale data" that identifies the bad call to useSelector. In react-redux 7.x, this additional call isn't made.

What is the expected behavior?

Here's the exact same code with version 7.2.9 of react-redux: https://codesandbox.io/s/react-redux-7-closure-4lq8ph?file=/src/App.js

Which browser and OS are affected by this issue?

No response

Did this work in previous versions of React Redux?

  • Yes
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant