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

Init currentLocation to initial location from the store #403

Merged
merged 1 commit into from
Jun 6, 2016
Merged
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
4 changes: 3 additions & 1 deletion src/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default function syncHistoryWithStore(history, store, {
}

let initialLocation
let currentLocation
let isTimeTraveling
let unsubscribeFromStore
let unsubscribeFromHistory
Expand All @@ -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 = () => {
Expand Down
27 changes: 27 additions & 0 deletions test/_createSyncTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down