You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 26, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 26, 2018. It is now read-only.
syncHistoryWithStore does not respect redux state #534
I am trying to restore the displayed page on app startup but it's always /, redux store is preloaded from local storage. HoweversyncHistoryWithStore erases the state.
I use redux-localstorage to persist redux to local storage which seems to be merging state from local storage into initialState therefore restoring the state without telling anyone which shouldn't be any different for the app when the concept of single source of truth is applied.
I am sure this issue can be reproduced with initialState with hardcoded route.
in my case initialLocation restored from state and is /connect and is the same as locationInStore, therefore syncHistoryWithStore does not attempt to restore the location.
That seems to be error prone in its essence:
// Init initialLocation with potential location in storeinitialLocation=getLocationInStore();
initialLocation === locationInStore will always be true on cold restart with state restored from local storage. This code will only work if we push new location first.
Why not to consult history for initial location? I mean, browser should know better right? When the app cold starts / is initial location of browser, but state has /connect set.
As a workaround we could simply enforce the transition to new route right after syncHistoryWithStore. Since syncHistoryWithStore will always reset the route to /, we could save the last visited location prior to the call and then feed it back, i.e:
Just a random note, it seems the syncHistoryWithStore method isn't a necessity in v5.0.0 as the middleware takes care of it. So perhaps if migrating to the alpha for that, no more issues? [outside of... the alpha thing]
It seems like react-router-redux v5.0.0 will fix a lot of things when using react-router 4.
But what about using immutable state, will a custom routerReducer do the job:
Activity
pronebird commentedon Feb 15, 2017
Debugging through
syncHistoryWithStorereveals that the following statement breaks:in my case
initialLocationrestored from state and is/connectand is the same aslocationInStore, thereforesyncHistoryWithStoredoes not attempt to restore the location.That seems to be error prone in its essence:
initialLocation === locationInStorewill always be true on cold restart with state restored from local storage. This code will only work if we push new location first.Why not to consult history for initial location? I mean, browser should know better right? When the app cold starts
/is initial location of browser, but state has/connectset.pronebird commentedon Feb 15, 2017
As a workaround we could simply enforce the transition to new route right after
syncHistoryWithStore. SincesyncHistoryWithStorewill always reset the route to/, we could save the last visited location prior to the call and then feed it back, i.e:rob2d commentedon Mar 27, 2017
Just a random note, it seems the syncHistoryWithStore method isn't a necessity in v5.0.0 as the middleware takes care of it. So perhaps if migrating to the alpha for that, no more issues? [outside of... the alpha thing]
MacKentoch commentedon Jul 12, 2017
It seems like react-router-redux v5.0.0 will fix a lot of things when using react-router 4.
But what about using immutable state, will a custom routerReducer do the job:
Or middleware will take care of it?
rowlandekemezie commentedon Oct 15, 2017
@MacKentoch have you gotten a workaround for your question ☝️
MacKentoch commentedon Oct 15, 2017
@mentrie I ended my starter with react-router-redux 4.x.x and wrote my own reducer.
I did not give a try to 5.x since I did have the use case in private or pro project then.
But, I keep interesting in new about it