-
-
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
Provider uses previous store for one additional render when store changes #1370
Comments
Workarounds I have right now:
|
If you can rewrite Provider to fix the behavior, please go ahead and file a PR. |
mpeyper
added a commit
to mpeyper/react-redux
that referenced
this issue
Aug 11, 2019
Fixes issue where the store and children got updated in different render passes which could result in mapState errors if the new children were not compatible with the old store. Fixes reduxjs#1370
markerikson
added a commit
that referenced
this issue
Aug 20, 2019
* Convert Provider into function component with hooks Fixes issue where the store and children got updated in different render passes which could result in mapState errors if the new children were not compatible with the old store. Fixes #1370 * Remove onStateChange from subscription when unsubscribing Co-Authored-By: Mark Erikson <[email protected]>
albertodev7
pushed a commit
to albertodev7/react-redux
that referenced
this issue
Dec 8, 2022
* Convert Provider into function component with hooks Fixes issue where the store and children got updated in different render passes which could result in mapState errors if the new children were not compatible with the old store. Fixes reduxjs#1370 * Remove onStateChange from subscription when unsubscribing Co-Authored-By: Mark Erikson <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
If a the
store
passed to aProvider
changes thestore
inReactReduxContext
does not update until the next render. This is causing me an issue thechildren
are changing, causing the to crash when trying tomapStateToProps
in that additional render.Sandbox.
Note: this is a contrived example to to show how this occurs, but I have an real world case using React Router V5 that has the same issue.
Also Note: my use case is not to have a distinct store per page, but actually using
redux-subspace
to create a virtual sub-store per page. Again, I didn't bother with this detail for the example as it occurs with real stores too.What is the expected behavior?
I would expect that if
Provider
permits me to change the store, that aconnect
ed component below it would not crash when rendering. I believe the root of the issue is the fact that the store is not updated in theProviders
's state untilcomponentDidUpdate
, but the render the would result in this update already has the newthis.props.children
value.I do concede that this is a pretty niche use case, and may not be the highest priority to fix (assuming you agree that it is an issue at all).
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?
The text was updated successfully, but these errors were encountered: