Skip to content

Commit 97e0d50

Browse files
authored
Add noTimeTravelDebugging prop (#455)
1 parent a105380 commit 97e0d50

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare module 'connected-react-router' {
2020
history: History<S>;
2121
context?: React.Context<ReactReduxContextValue>;
2222
noInitialPop?: boolean;
23+
noTimeTravelDebugging?: boolean;
2324
omitRouter?: boolean;
2425
}
2526

src/ConnectedRouter.js

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const createConnectedRouter = (structure) => {
2525

2626
// Subscribe to store changes to check if we are in time travelling
2727
this.unsubscribe = store.subscribe(() => {
28+
// Allow time travel debugging compatibility to be turned off
29+
// as the detection for this (below) is error prone in apps where the
30+
// store may be unmounted, a navigation occurs, and then the store is re-mounted
31+
// during the app's lifetime. Detection could be much improved if Redux DevTools
32+
// simply set a global variable like `REDUX_DEVTOOLS_IS_TIME_TRAVELLING=true`.
33+
const isTimeTravelDebuggingAllowed = !props.noTimeTravelDebugging
34+
2835
// Extract store's location
2936
const {
3037
pathname: pathnameInStore,
@@ -42,6 +49,7 @@ const createConnectedRouter = (structure) => {
4249

4350
// If we do time travelling, the location in store is changed but location in history is not changed
4451
if (
52+
isTimeTravelDebuggingAllowed &&
4553
props.history.action === 'PUSH' &&
4654
(pathnameInHistory !== pathnameInStore ||
4755
searchInHistory !== searchInStore ||
@@ -118,6 +126,7 @@ const createConnectedRouter = (structure) => {
118126
children: PropTypes.oneOfType([ PropTypes.func, PropTypes.node ]),
119127
onLocationChanged: PropTypes.func.isRequired,
120128
noInitialPop: PropTypes.bool,
129+
noTimeTravelDebugging: PropTypes.bool,
121130
stateCompareFunction: PropTypes.func,
122131
omitRouter: PropTypes.bool,
123132
}

0 commit comments

Comments
 (0)