autoRehydrate does not lift the reducer it makes
See original GitHub issueFinally found the root cause…
Problem:
if you use redux-devtools & call replaceReducer, the initial state overrides the persisted state.
Reason:
replaceReducer doesn’t know about the reducerEnhancer that autoRehydrate() creates. That means the devtools inits without it, and doesn’t merge the initial state with the persisted state.
Reproduction:
Call store.replaceReducer on an async route. (Probably works on sync routes, too. Haven’t tried).
Workarounds: None (use redux-storage?)
Fix:
Either offer a reducerEnhancer like redux-storage or lift the replaceReducer into the liftedStore. I think the former is cleaner because autoRehydrate does not need a lifted store, so using a higher-level API seems reasonable.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
What is the use of autoRehydrate in redux-persist and why it ...
autoRehydrate means calling for the persist/REHYDRATE action to read the persisted state from the disk (which you have persisted before) ...
Read more >redux-persist - npm
Auto rehydrate is a higher order reducer that automatically rehydrates state. While auto rehydration works out of the box, individual reducers ...
Read more >vovkasm/redux-persist v4.10.1 - npm.io
autoRehydrate is a store enhancer that automatically rehydrates state. While auto rehydration works out of the box, individual reducers can opt in to...
Read more >[Solved]-Adding style attribute in react-Reactjs
There is a logic error in your example code. The css are not updated, only the text. So use the ternary to change...
Read more >Redux Persist Blacklist Deleting Reducers? - ADocLib
Hi I was trying to make only one reducer persist like in my code below: I've got a react redux app and using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

the latest version now lifts the reducer. I am using it in a HMR environment and it works. If there are outstanding issues please reopen!
@mattkrick thanks for the reference now i understand what you mean by lifted reducer 😃
I believe we can classify this as a bug, and fix by lifting the reducer in v3. For v4 I will reconsider the higher order reducer option.
redux-storage is a great choice as well, I am glad that worked out. Redux persist does a lot to be performant out of the box, hopefully after we get all of this sorted you can give it another try 👍