From 02a25876f377d8088e56bdc5a998ec2826ea056b Mon Sep 17 00:00:00 2001 From: Nick Galloway Date: Thu, 17 Sep 2020 15:26:13 -0700 Subject: [PATCH] Add noTimeTravelDebugging prop --- index.d.ts | 1 + src/ConnectedRouter.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/index.d.ts b/index.d.ts index a7cc5dbd..f2e7bcc5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -20,6 +20,7 @@ declare module 'connected-react-router' { history: History; context?: React.Context; noInitialPop?: boolean; + noTimeTravelDebugging?: boolean; omitRouter?: boolean; } diff --git a/src/ConnectedRouter.js b/src/ConnectedRouter.js index 401925bd..95a176ad 100644 --- a/src/ConnectedRouter.js +++ b/src/ConnectedRouter.js @@ -25,6 +25,13 @@ const createConnectedRouter = (structure) => { // Subscribe to store changes to check if we are in time travelling this.unsubscribe = store.subscribe(() => { + // Allow time travel debugging compatibility to be turned off + // as the detection for this (below) is error prone in apps where the + // store may be unmounted, a navigation occurs, and then the store is re-mounted + // during the app's lifetime. Detection could be much improved if Redux DevTools + // simply set a global variable like `REDUX_DEVTOOLS_IS_TIME_TRAVELLING=true`. + const isTimeTravelDebuggingAllowed = !props.noTimeTravelDebugging + // Extract store's location const { pathname: pathnameInStore, @@ -42,6 +49,7 @@ const createConnectedRouter = (structure) => { // If we do time travelling, the location in store is changed but location in history is not changed if ( + isTimeTravelDebuggingAllowed && props.history.action === 'PUSH' && (pathnameInHistory !== pathnameInStore || searchInHistory !== searchInStore || @@ -118,6 +126,7 @@ const createConnectedRouter = (structure) => { children: PropTypes.oneOfType([ PropTypes.func, PropTypes.node ]), onLocationChanged: PropTypes.func.isRequired, noInitialPop: PropTypes.bool, + noTimeTravelDebugging: PropTypes.bool, stateCompareFunction: PropTypes.func, omitRouter: PropTypes.bool, }