diff --git a/src/sync.js b/src/sync.js index ee68f79..ce98560 100644 --- a/src/sync.js +++ b/src/sync.js @@ -34,6 +34,7 @@ export default function syncHistoryWithStore(history, store, { let isTimeTraveling let unsubscribeFromStore let unsubscribeFromHistory + let currentLocation // What does the store say about current location? const getLocationInStore = (useInitialIfEmpty) => { @@ -42,14 +43,14 @@ export default function syncHistoryWithStore(history, store, { (useInitialIfEmpty ? initialLocation : undefined) } - // Init currentLocation with potential location in store - let currentLocation = getLocationInStore() + // Init initialLocation with potential location in store + initialLocation = getLocationInStore() // If the store is replayed, update the URL in the browser to match. if (adjustUrlOnReplay) { const handleStoreChange = () => { const locationInStore = getLocationInStore(true) - if (currentLocation === locationInStore) { + if (currentLocation === locationInStore || initialLocation === locationInStore) { return } diff --git a/test/_createSyncTest.js b/test/_createSyncTest.js index 34aa7b3..ee4268a 100644 --- a/test/_createSyncTest.js +++ b/test/_createSyncTest.js @@ -186,6 +186,13 @@ export default function createTests(createHistory, name, reset = defaultReset) { // We expect that we get a single call to history expect(historyListen.calls.length).toBe(1) + clientStore.dispatch({ + type: 'non-router' + }) + + // We expect that we still get only a single call to history after a non-router action is dispatched + expect(historyListen.calls.length).toBe(1) + historyUnsubscribe() }) })