redux-devtools icon indicating copy to clipboard operation
redux-devtools copied to clipboard

replaceReducer with shouldHotReload: false erases action history

Open bdwain opened this issue 8 years ago • 12 comments

I am trying to implement code splitting in my app, and I call replaceReducer when a new reducer is loaded. I use the shouldHotReload: false option to avoid rerunning actions, but now the actions dispatched before replaceReducer are erased from the action history when viewing the devtools. I just see @@Init and then ASYNC_LOAD_COMPLETE, which is dispatched after replaceReducer runs successfully.

Is it possible to preserve the state transitions and actions from before replaceReducer?

Note: I am using the redux devtools chrome extension, so it may just be an issue in that project. But since it uses this library, I just assumed this behavior came from here and not there. If that's wrong I can refile with them.

bdwain avatar Aug 08 '17 20:08 bdwain

Running into the same issue - all state transitions prior to replaceReducer() being called disappear (although the actions themselves still appear in the Inspector and Log monitor views).

jmar777 avatar Sep 18 '17 23:09 jmar777

See more details in this issue: https://github.com/reduxjs/redux-devtools/issues/559.

Methuselah96 avatar Aug 28 '20 21:08 Methuselah96

@Methuselah96 would you accept a PR to fix this? This is causing issues with the redux-injectors library that I help maintain

BenLorantfy avatar Apr 24 '21 17:04 BenLorantfy

My half-informed suspicion is that there might not be a feasible resolution, because the DevTools relies on replaying actions to show the state at that point in time. If a reducer gets swapped out now, running the "old" actions through it would presumably result in states that don't match what the state was when the original dispatches happened. Happy to be proven wrong here, but that's my first thought.

markerikson avatar Apr 24 '21 18:04 markerikson

One option to improve it would be to store old reducers as well as the current one, so that when replaying actions, it uses the reducer that was current at that time.

Another would be to show the action history but disable replayability before the last call to replaceReducers.

I think both of those would be an improvement over the current behavior. Thoughts?

bdwain avatar Apr 25 '21 04:04 bdwain

Hmm. That could hypothetically work, although there'd have to be bookkeeping to know which actions were dispatched when a given reducer was in use.

markerikson avatar Apr 25 '21 16:04 markerikson

I know this thread is somewhat dead, but I wonder if there's a way to differentiate between the replaceReducer used by the hot reload and user usage of the replaceReducer function. It's actually really annoying having to set shouldHotReload to false, simply because I'm trying to code split my reducers and use the devtools.

DanielCashlink avatar Apr 25 '22 16:04 DanielCashlink

Still running into this issue, which is really annoying, is there any progress with it ?

piechoo avatar Aug 19 '22 09:08 piechoo