Skip to content

[BUG] LOCATION_CHANGE called on each new reducer injected in store #119

@remitestut

Description

@remitestut

Hello,

I'm trying to replace connected-react-router by your library.
I'm using react-router-dom v6.
Everything looks fine but I got a problem when injecting new reducer in my store.
On each new reducer injected, LOCATION_CHANGE action is called.
I didn't have this issue with connected-react-router and react-router-dom v5.

Here is my code to reproduce the problem :

const {
    createReduxHistory,
    routerMiddleware,
    routerReducer
} = createReduxHistoryContext({ history: createBrowserHistory() });

const reducers = {
    ...staticReducers,
    router: routerReducer,
}

const createReducer = (staticReducers, addeddReducers) => combineReducers({ ...staticReducers, ...addeddReducers });

const store = configureStore({
    reducer: reducers,
    middleware: getDefaultMiddleware => {
        return getDefaultMiddleware({
            immutableCheck: false,
            serializableCheck: false,
        })
            .concat(routerMiddleware)
    },
});

store.asyncReducers = {};
store.injectReducer = (key, reducer) => {
    store.asyncReducers[key] = reducer;
    store.replaceReducer(createReducer(reducers, store.asyncReducers));
}

const history = createReduxHistory(store);

store.injectReducer("reducerToAdd", reducerToAdd);

const bootApplication = async () => {
    const appRoot = createRoot(document.getElementById("root"));

    appRoot.render(
        <ReduxProvider store={store}>
            <HistoryRouter history={history}>
                NOTHING TO SEE
                <Link to={"another/route"}>TEST</Link>
            </HistoryRouter>
        </ReduxProvider>
    );
};

bootApplication();

Did I forgot something ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions