Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 41 ยท Testing and Tooling

Redux DevTools and Debugging

Use the Redux DevTools extension for the action log, state diffs and time travel, configure it in Redux Toolkit, sanitize sensitive data, and debug common Redux problems step by step.

Redux's big promise for debugging is that every state change is an action in a list. If you can see that list and the state before and after each action, most bugs show themselves: "this action never fired", "this reducer returned the wrong thing", "this component read the wrong slice". The Redux DevTools browser extension (Chrome, Firefox, Edge) shows exactly that.

What the DevTools give you

  • Action log: every dispatched action in order, with its type and payload. Actions from thunks, RTK Query and listeners appear too.
  • State and Diff tabs: the whole state after an action, or just what changed.
  • Time travel: click an earlier action to jump back; the app re-renders with the state at that moment. Because reducers are pure, this is just "use an older state".
  • Skip/toggle an action: remove one action from history and replay all the others, to find the one that breaks things.
  • Trace: the call stack that dispatched an action (enable the "trace" option) so you can find the component or thunk responsible.
  • Chart, Test and Export: visualize the state tree, generate test skeletons, export or import a recorded session to share a bug report.
  • Dispatcher: send a hand-written action to the running app.

Turning it on

configureStore enables the DevTools connection automatically in development and turns it off in production. You can configure it:

JavaScript
// Real Redux Toolkit code (read-only)
const store = configureStore({
  reducer,
  devTools: process.env.NODE_ENV !== 'production' && {
    name: 'My app',
    trace: true,
    traceLimit: 25,
    actionsDenylist: ['mouse/moved'],               // hide noisy actions
    actionSanitizer: (action) =>
      action.type === 'auth/login' ? { ...action, payload: '[REDACTED]' } : action,
    stateSanitizer: (state) => ({ ...state, auth: { ...state.auth, token: '[REDACTED]' } }),
  },
});

Use sanitizers if your state or actions hold secrets, since a recorded session export contains them. If you need DevTools in production for some reason, protect them behind a flag; they keep a copy of history in memory, which costs performance.

With plain Redux (without Toolkit) use the @redux-devtools/extension package's composeWithDevTools.

How time travel works (a stand-in)

The extension is not available in the editor, but its core is small: a recorder that logs (action, state) pairs, and a "jump" that re-applies actions from a chosen point. This stand-in records everything and lets you jump back, toggle an action off and replay.

JS A mini action log with time travel

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The balance ends at 0. Skipping the first fee action and replaying gives 15, which shows how much that action contributed. That is how you find "the action that broke things" in a long session. Time travel only works because reducers are pure and state is serializable. A reducer that reads Date.now() or a random number would replay differently each time.

Debugging checklist

When something is wrong, walk the data flow in order. Each step has a place to look:

flowchart LR
  A["1. Was the action<br/>dispatched?"] --> B["2. Did the reducer<br/>handle it?"]
  B --> C["3. Is the state<br/>correct?"]
  C --> D["4. Does the selector<br/>read the right path?"]
  D --> E["5. Did the component<br/>re-render?"]

Debug in the direction the data flows.

  1. The action never appears in the log. The event handler is not wired, dispatch was never called (dispatch(fetchUser) instead of dispatch(fetchUser(7))), or middleware swallowed it. Add a temporary logger middleware.
  2. The action appears but the state does not change. Compare the action type string with the one the reducer handles (typos, a different slice name prefix). Check the Diff tab: no diff means the reducer ignored or mutated. If you mutate outside Immer, Redux Toolkit throws in development; plain Redux silently fails (see Immer).
  3. The state changes, but the UI does not. The selector reads the wrong path, or returns the same reference because of a mutation, or the component is not wrapped in the Provider.
  4. The UI re-renders too often. See re-renders and performance: look for selectors that return new objects.
  5. State is wrong only after reload. Look at persistence and rehydration (migrations).

Useful errors from Redux Toolkit in development

Message Meaning
"A non-serializable value was detected in an action/state" You put a Promise, function, class instance or Date into an action or state
"Invariant failed: A state mutation was detected..." Something mutated state outside a draft; the message names the path
"Cannot assign to read only property" Mutation of a frozen object (usually in a component or selector)
"Selector ... returned a different result when called with the same parameters" The selector builds a new object or array each call; memoize it
"Warning: Middleware for RTK-Query API ... not added" api.middleware is missing from the store

Fix the cause rather than disabling the check. If a non-serializable value is truly required (for example redux-persist actions), ignore only those action types in serializableCheck.

Other debugging tools

  • React DevTools: components tab (props, hooks) and Profiler ("why did this render?").
  • console.log(current(state)) inside Immer reducers (not console.log(state), which prints a Proxy).
  • The browser console: expose the store temporarily with window.store = store in development to run store.getState() and store.dispatch(...) by hand.
  • A logger middleware such as the one in writing custom middleware for environments without the extension (React Native has Reactotron, Flipper and standalone DevTools).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does time travel work in Redux?

    Pure reducers plus serializable actions mean replay is deterministic.
  2. 2. An action appears in the log but the Diff tab is empty. What does that suggest?

    No diff means the reducer returned the same state.
  3. 3. How can you stop the DevTools from recording an auth token?

    Sanitizers replace values before they reach the extension.
  4. 4. dispatch(fetchUser) logs nothing and the request never starts. Why?

    It must be dispatch(fetchUser(7)).

Summary

  • Redux DevTools show actions, state, diffs and traces, and allow time travel and action skipping.
  • configureStore connects them in development; use sanitizers and denylists for secrets and noise.
  • Debug in the direction of data flow: action, reducer, state, selector, render.
  • Redux Toolkit's development errors point to mutation, serialization and selector-stability bugs.
  • Time travel requires pure reducers and serializable state.

Next: TypeScript with Redux Toolkit