diff --git a/packages/rudy/src/core/createReducer.js b/packages/rudy/src/core/createReducer.js index fd005533c..e96270b72 100644 --- a/packages/rudy/src/core/createReducer.js +++ b/packages/rudy/src/core/createReducer.js @@ -26,7 +26,7 @@ export default (initialState: Object, routes: Routes) => ( return { ...st, ...act, ...location } } - if (r && r.path && (l.url !== st.url || /load|reset/.test(l.kind))) { + if (r && r.path) { const { type, params, query, state, hash, basename } = action const { universal } = st const s = { type, params, query, state, hash, basename, universal, ...l } diff --git a/packages/rudy/src/core/createRouter.js b/packages/rudy/src/core/createRouter.js index f0e8ab19a..f49f73b61 100644 --- a/packages/rudy/src/core/createRouter.js +++ b/packages/rudy/src/core/createRouter.js @@ -28,6 +28,7 @@ import { pathlessRoute, anonymousThunk, transformAction, + preventDoubleDispatch, call, enter, changePageTitle, @@ -41,6 +42,7 @@ export default ( anonymousThunk, pathlessRoute('thunk'), transformAction, // pipeline starts here + preventDoubleDispatch, // Hydrate: skip callbacks called on server to produce initialState (beforeEnter, thunk, etc) // Server: don't allow client-centric callbacks (onEnter, onLeave, beforeLeave) call('beforeLeave', { prev: true }), diff --git a/packages/rudy/src/middleware/index.js b/packages/rudy/src/middleware/index.js index b8064b71b..7ef33727b 100644 --- a/packages/rudy/src/middleware/index.js +++ b/packages/rudy/src/middleware/index.js @@ -1,4 +1,5 @@ export { default as transformAction } from './transformAction' +export { default as preventDoubleDispatch } from './preventDoubleDispatch' export { default as enter } from './enter' export { default as call, shouldCall } from './call' diff --git a/packages/rudy/src/middleware/preventDoubleDispatch.js b/packages/rudy/src/middleware/preventDoubleDispatch.js new file mode 100644 index 000000000..ad7dcbe80 --- /dev/null +++ b/packages/rudy/src/middleware/preventDoubleDispatch.js @@ -0,0 +1,5 @@ +export default () => (req, next) => { + if (!req.route.path) return next() + if (req.isDoubleDispatch()) return req.handleDoubleDispatch() // don't dispatch the same action twice + return next() +} diff --git a/packages/rudy/src/middleware/transformAction/index.js b/packages/rudy/src/middleware/transformAction/index.js index 31ff98906..407bb1a69 100644 --- a/packages/rudy/src/middleware/transformAction/index.js +++ b/packages/rudy/src/middleware/transformAction/index.js @@ -5,8 +5,6 @@ export default () => (req, next) => { req.action = formatAction(req) - if (req.isDoubleDispatch()) return req.handleDoubleDispatch() // don't dispatch the same action twice - const { type, params, query, state, hash, basename, location } = req.action Object.assign(req, { type, params, query, state, hash, basename, location }) // assign to `req` for conevenience (less destructuring in callbacks)