diff --git a/src/sync.js b/src/sync.js index ee68f79..e9fea8b 100644 --- a/src/sync.js +++ b/src/sync.js @@ -74,9 +74,6 @@ export default function syncHistoryWithStore(history, store, { return } - // Remember where we are - currentLocation = location - // Are we being called for the first time? if (!initialLocation) { // Remember as a fallback in case state is reset @@ -88,6 +85,9 @@ export default function syncHistoryWithStore(history, store, { } } + // Remember where we are + currentLocation = location + // Tell the store to update by dispatching an action store.dispatch({ type: LOCATION_CHANGE, diff --git a/test/_createSyncTest.js b/test/_createSyncTest.js index 34aa7b3..e2c4df5 100644 --- a/test/_createSyncTest.js +++ b/test/_createSyncTest.js @@ -164,7 +164,7 @@ export default function createTests(createHistory, name, reset = defaultReset) { }) describe('Server', () => { - it('handles inital load correctly', () => { + it('handles initial load correctly', () => { // Server const { store: serverStore } = createSyncedHistoryAndStore(createHistory('/')) expect(serverStore).toContainLocation({ @@ -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() }) })