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

Fix current location being set unnecessaily with server side rendering #412

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion test/_createSyncTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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()
})
})
Expand Down