diff --git a/src/sync.js b/src/sync.js index 361aa61..ee68f79 100644 --- a/src/sync.js +++ b/src/sync.js @@ -31,7 +31,6 @@ export default function syncHistoryWithStore(history, store, { } let initialLocation - let currentLocation let isTimeTraveling let unsubscribeFromStore let unsubscribeFromHistory @@ -43,6 +42,9 @@ export default function syncHistoryWithStore(history, store, { (useInitialIfEmpty ? initialLocation : undefined) } + // Init currentLocation with potential location in store + let currentLocation = getLocationInStore() + // If the store is replayed, update the URL in the browser to match. if (adjustUrlOnReplay) { const handleStoreChange = () => { diff --git a/test/_createSyncTest.js b/test/_createSyncTest.js index 2aec90c..34aa7b3 100644 --- a/test/_createSyncTest.js +++ b/test/_createSyncTest.js @@ -163,6 +163,33 @@ export default function createTests(createHistory, name, reset = defaultReset) { }) }) + describe('Server', () => { + it('handles inital load correctly', () => { + // Server + const { store: serverStore } = createSyncedHistoryAndStore(createHistory('/')) + expect(serverStore).toContainLocation({ + pathname: '/', + action: 'POP' + }) + + // Client + let clientStore = createStore(combineReducers({ + routing: routerReducer + }), serverStore.getState()) + let clientHistory = useRouterHistory(createHistory)() + + const historyListen = expect.createSpy() + const historyUnsubscribe = clientHistory.listen(historyListen) + + syncHistoryWithStore(clientHistory, clientStore) + + // We expect that we get a single call to history + expect(historyListen.calls.length).toBe(1) + + historyUnsubscribe() + }) + }) + describe('Redux DevTools', () => { let originalHistory, history, store, devToolsStore