Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit 5dfe011

Browse files
committed
Restore path on Devtools reset
1 parent 8422f9f commit 5dfe011

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@ function replacePath(path, state, { avoidRouterUpdate = false } = {}) {
3333

3434
// Reducer
3535

36-
const initialState = {
37-
changeId: 1,
38-
path: undefined,
39-
state: undefined,
40-
replace: false
41-
};
36+
// The initial path is needed when resetting the state in Devtools but is
37+
// unknown until the history.listen callback set up in syncReduxAndRouter fires
38+
let initialRoute;
39+
40+
function initialState() {
41+
return {
42+
changeId: 1,
43+
state: undefined,
44+
replace: false,
45+
path: initialRoute && initialRoute.path
46+
}
47+
}
4248

43-
function update(state=initialState, { type, payload }) {
49+
function update(state=initialState(), { type, payload }) {
4450
if(type === UPDATE_PATH) {
4551
return Object.assign({}, state, {
4652
path: payload.path,
@@ -75,6 +81,8 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
7581
state: location.state
7682
};
7783

84+
if(!initialRoute) initialRoute = route;
85+
7886
// Avoid dispatching an action if the store is already up-to-date,
7987
// even if `history` wouldn't do anything if the location is the same
8088
if(locationsAreEqual(getRouterState(), route)) return;

0 commit comments

Comments
 (0)