-
Notifications
You must be signed in to change notification settings - Fork 644
Restore router state #252
Comments
Right now we don't handle resets in Dev Tools. I'm pretty sure we can listen to Dev Tool's RESET actions, but that's the crux of the issue. |
Also, are you running the master version or an older release? I only fixed the initialState stuff yesterday and haven't released that yet. |
Also even if the resets were working, I think you'd get burned in this case because the location action is a POP - #164 |
@timdorr it doesn't work if I use the source from the master or from the last release. @mjrussell it doesn't work if hack action method to |
It shouldn't. I just wanted to make sure you're talking about 2.0. |
Ok, how I can solve this? Do you have any idea? |
We have to build support for the dev tools actions. We'll get to that soon, I'm sure. |
Good, but it's not about dev tools. Maybe you know the different way to setup location on app start? |
Your browser or server request determines that. The next version will set the initial location in state properly. But it's a constant. You can't open a location and say you're somewhere else. If you need to do an immediate redirect, you can do that in your app code somewhere. |
That’s not how DevTools work. They are not meant to expose their internal actions to any other thing. When you press Reset in DevTools, from the app’s point of view, subscriptions fire, and Unfortunately I can’t tell whether the author is using I’m also not sure whether |
Oh, I can see now you already know that well: a00acfd. |
I misspoke about the RESET action. Just postulating some ideas without looking at code 😄
That's pretty much all it does. It looks at the location in state and compares it with the last known location I'm at a loss for why the RESET doesn't transition, but I haven't played with it much to diagnose. This (along with capturing router state) is on my shortlist of things needing to be fixed in the library right now. |
Yeah, that specific error is fixed. Doesn't reset, though. I'm going to see about comparing against initialState, though. |
I'm pretty sure we're running into #164 now. |
While 3ae8110 fixed the POP problem I still think we disregard the initial state. import { persistState } from 'redux-devtools'
// ...
export default function configureStore(initialState) {
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(thunk, api, reduxRouterMiddleware, createLogger()),
DevTools.instrument(),
persistState('lol')
)
) With |
I see parts to fixing this:
middleware.listenForReplays =
(store, selectLocationState = SELECT_LOCATION) => {
const getLocationState = () => selectLocationState(store.getState())
const initialLocation = getLocationState()
const reconcileLocationWithState = () => {
const location = getLocationState()
// If we're resetting to the beginning, use the saved initial value. We
// need to dispatch a new action at this point to populate the store
// appropriately.
if (!location) {
history.transitionTo(initialLocation)
return
}
// Otherwise, if we need to update the history location, do so without
// dispatching a new action, as we're just bringing history in sync
// with the store.
if (location.key !== currentKey) {
syncing = true
history.transitionTo(location)
syncing = false
}
}
unsubscribeStore = store.subscribe(reconcileLocationWithState)
reconcileLocationWithState() // <------------------- this is important
}
??? |
What if we move the initial dispatch into a separate method? a la const disconnect = middleware.connect() Then we could change |
Thanks for looking into this. I'm not a Dev Tools user, so it helps to have a second set of eyes with more experience. I agree with that behavior. I got tripped up a bit by
I'm not a fan of configuration over convention. I'd rather have the opt-in be a function call to enable the behavior. |
Let me send a PR and we’ll discuss there :-) |
Let’s discuss in #255. |
BTW, if reset support actually is broken, we should remove or amend this test case - https://github.com/rackt/react-router-redux/blob/b6a9c1bb51521bf6f5f416de394658d586683d9f/test/createTests.js#L218-L235. |
👍 |
I use react-router-redux for sync history. I want to save the state of an application and restore it in the future. All components wich connected to redux work fine with restored state wich I transfer by initial state. But! Router doesn't understand :( What is wrong?
I got
/
;(The text was updated successfully, but these errors were encountered: