Skip to content

Commit

Permalink
Add noTimeTravelDebugging prop (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackarctic committed Feb 22, 2021
1 parent a105380 commit 97e0d50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Expand Up @@ -20,6 +20,7 @@ declare module 'connected-react-router' {
history: History<S>;
context?: React.Context<ReactReduxContextValue>;
noInitialPop?: boolean;
noTimeTravelDebugging?: boolean;
omitRouter?: boolean;
}

Expand Down
9 changes: 9 additions & 0 deletions src/ConnectedRouter.js
Expand Up @@ -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,
Expand All @@ -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 ||
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 97e0d50

Please sign in to comment.