-
-
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
Dispatching at the same time as setState causes two renderings #1912
Comments
Since the video was difficult to understand, I upload the original video file. |
Without having fully investigated yet: batching and render timing are owned by React, not React-Redux. We don't have full control over that. I would have expected that all updates queued in a Either way I don't think there's anything we can specifically do here, and I don't think this is actually a "bug". |
The OP has used But, unfortunately, I could made another repro for this issue, without StrictMode. Actually, the example I have made can be fixed, if you use dependencies for the useEffect. |
Yes, it's actually that. Good call! |
Isn't that still a problem that we should maybe bring up with the React team? |
Andarist pointed out this is likely the same thing as facebook/react#24831 |
It seems like problem is more complex than just rendering twice. Dispatching redux action in the same effect where a local state is updated cancels the local state update. I've created a codesandbox with a simple to reproduce example. https://codesandbox.io/s/friendly-worker-fdyvqk Probably it's on React side as mentioned but posting here maybe it will be helpful. |
This will be changed on the React side - unfortunately at this point there's not really anything we can do about it: facebook/react#25191 (comment) |
Update: this is hopefully fixed in React 19: |
What version of React, ReactDOM/React Native, Redux, and React Redux are you using?
What is the current behavior?
Synchronous calls to dispatch and setState within useEffect will cause separate re-rendering.
Since it may not be possible to check visually, try using the Profiler in the React Developer Tools to see how it works.
https://codesandbox.io/s/brave-dew-cc7p4p?file=/src/features/counter/CounterEditor.tsx
What is the expected behavior?
The re-rendering occurs only once.
Which browser and OS are affected by this issue?
Chrome/100.0.4896.127, Windows10
Did this work in previous versions of React Redux?
The text was updated successfully, but these errors were encountered: