Question
UI Stale After In-Place State Mutation in Redux Reducer
Sora Dey
0 reputation · 28 Jul 2023, 17:56 UTC
149K views0
Goal: Understand if a Redux reducer that mutates state in place and returns the original reference causes React Redux subscribers to skip re‑renders, and how this behavior varies between React Redux versions and selector configurations.
Constraints: The reducer must not return a new reference; the store is not frozen; selectors use default shallow equality unless a custom comparator is provided. The UI component uses useSelector (or connect) to read a nested field that was altered by the mutation.
Uncertainty: Whether React Redux v7’s subscription logic differs from v8’s batching, and if a custom equality function can rescue re‑renders despite the unchanged reference.
Questions:
- Does a reducer that mutates nested state in place and returns the same reference always prevent a useSelector re‑render in React Redux v7 and v8?
- Does supplying a custom equality function to useSelector cause a re‑render when the state reference is unchanged but the nested value changed?
- Does enabling the Redux DevTools “trace” option change the outcome by forcing a shallow comparison?