question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reducer is called with previously performed actions when asynchronously loading another reducer

See original GitHub issue

Seeing a weird bug only when I use the extension (2.5.1.9). Not using it with Vanilla DevTools. Have followed instructions in the README to set it up.

The bug is: my reducer is called with previous actions when asynchronously loading another reducer.

Say I perform actions say ACTION_X and ACTION_Y in a page. I leave the page and go to another where the new page’s reducer is injected. When this happens the previous page’s reducer is called with all the actions I performed in that page (ACTION_X & ACTION_Y).

I can confirm the actions are not dispatched from my code after I leave the page and also they do not show up in the extension. I think it’s caused because of the reducer injection. Because if I navigate to a page which does not have a reducer this won’t happen.

What’s weird about this is it happens only for two of the 5 actions I have in the page. Have not observed it in other pages.

Any help to debug this further is much appreciated.

My app uses React Router with Webpack code splitting and I’m asynchronously injecting reducers on a route load like this:

{
     path: "somePath",
     getComponent(location, cb) {
         require.ensure([],
             require => {
                 injectReducer('reducerName', require('./pages/SomePage/SomePage.reducer').default);
                     cb(null, CreateModel);
                  }
              )
            }
       }
}

where injectReducer is:

function injectAsyncReducer(store) {
    return (name, asyncReducer) => {
        store.asyncReducers[name] = asyncReducer; 
        store.replaceReducer(createReducer(store.asyncReducers));
    };
}

injectReducer = injectAsyncReducer(store);

and my createReducer looks like this

export default function createReducer(asyncReducers) {
    const appReducer = combineReducers({
        ...asyncReducers
    });

    return (state, action) => {
        return appReducer(state, action)
    };
};

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
zalmoxisuscommented, Oct 4, 2016

I have just published v2.7.0 where you can fix that behaviour by specifying shouldHotReload parameter to false like:

  const composeEnhancers =
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?   
      window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
        shouldHotReload: false
      }) : compose;

  const enhancer = composeEnhancers(
    applyMiddleware(...middleware),
    // other store enhancers if any
  );
  const store = createStore(reducer, enhancer);

See the release notes for more details. Feel free to reopen the issue if it doesn’t help.

0reactions
skosnocommented, Sep 19, 2016

Is there any way to go around this issue? Disabling devtools is an option but would prefer to have them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux Fundamentals, Part 3: State, Actions, and Reducers
Reducers are functions that take the current state and an action as arguments, and return a new state result. In other words, (state,...
Read more >
store.replaceReducer call previous reducer again · Issue #2967
I use store.replaceReducer to load async module reducers,when I dispath an action in first module, reducer called as expect,but when async ...
Read more >
Accessing a part of reducer state from one reducer within ...
A reducer cannot access another reducer's state, but if you're using redux-thunk you can do so from within an action creator.
Read more >
Managing Complexity in Redux: Higher-Order Reducers and ...
This post follows the story of an app which has been built with Redux but has somewhere, somehow taken a turn for the...
Read more >
Methods for tracking action status in Redux - LogRocket Blog
In Redux, each dispatched action executes all the reducers, regardless of whether a given reducer is even supposed to handle it. By creating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found