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

Commit 3db2cfa

Browse files
committed
Delay first listen until after middleware setup.
No other way to do this outside of a setTimeout. Because history.listen is synchronous, it can dispatch an action before the middleware is finished being set up and points to a vanilla dispatch function. Fixes #193
1 parent 524898b commit 3db2cfa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ export function syncHistory(history) {
4848
let connected = false, syncing = false
4949

5050
function middleware(store) {
51-
unsubscribeHistory = history.listen(location => {
52-
currentKey = location.key
53-
if (syncing) {
54-
// Don't dispatch a new action if we're replaying location.
55-
return
56-
}
51+
setTimeout(() => {
52+
unsubscribeHistory = history.listen(location => {
53+
currentKey = location.key
54+
if (syncing) {
55+
// Don't dispatch a new action if we're replaying location.
56+
return
57+
}
5758

58-
store.dispatch(updateLocation(location))
59-
})
59+
store.dispatch(updateLocation(location))
60+
})
61+
}, 0)
6062

6163
connected = true
6264

0 commit comments

Comments
 (0)