next-redux-wrapper
next-redux-wrapper copied to clipboard
Recursive call HYDRATE, can anyone help?

`import { createWrapper, HYDRATE } from "next-redux-wrapper"; import { configureStore, applyMiddleware, Store } from "@reduxjs/toolkit"; import createSagaMiddleware, { Task } from "redux-saga"; import Immutable from "seamless-immutable";
import { loggerNext } from "../middlewares/loggerReduxSagaNext"; import rootReducer from "./root-redux"; import rootSaga from "./root-saga";
export interface SagaStore extends Store { sagaTask?: Task; }
const hydrate = (state, action) => { if (action.type === HYDRATE) { return Immutable({ ...state, ...action.payload }); }
return rootReducer(state, action); };
const makeStore = () => { const sagaMiddleware = createSagaMiddleware();
const store = configureStore({ reducer: hydrate, enhancers: [applyMiddleware(sagaMiddleware, loggerNext)], devTools: process.env.NODE_ENV === "development", });
(store as SagaStore).sagaTask = sagaMiddleware.run(rootSaga);
return store; };
export const storeWrapper = createWrapper(makeStore, { debug: false, }); `
I have the same problem, I fixed it but I don't think it is the correct way store.ts
const store = configureStore({
reducer: {
[serverAuthSlice.name]: serverAuthSlice.reducer,
[clientAuthSlice.name]: clientAuthSlice.reducer
},
devTools: true,
});
export const makeStore = () => store;
And I don't user wrapper.getStatic, wrapper.getServerSide etc... Instead I use a normal getServerSide props and I import the makeStore function:
const auth = makeStore().getState().serverAuth
I really don't think it is the good solution because you don't get hydrates anymore. But in my case there is no problem not having hydrates
@kirill-konshin Is this correct ?
I have this problem after updating dependencies. I found the problem using the exclusion method.
The problem to react-redux v. 8.0.2
for some reason happens as described above - a "Recursive call HYDRATE".
There is no such problem with react-redux v. 7.2.8
.
Also, the problem disappear with next-redux-wrapper v. 8.0.0-rc.1
+ react-redux v. 8.0.2
.
Hope this helps you ^__^
I apologize for my English ^__^~
@DimkaSklyar thanks! I installed react-redux v 7.2.8 and the problem does indeed disappear.
I also had to switch reactStrictMode: false in my next.config.js to prevent it running twice.
Now it's behaving as it should.
Probably related to #472 😊
@DimkaSklyar Thank you, I was troubleshooting the problem for weeks and you presented me such a nice solution. Problem dissappeared after changing dependencies, many thanks to you! :)