next-redux-wrapper icon indicating copy to clipboard operation
next-redux-wrapper copied to clipboard

Recursive call HYDRATE, can anyone help?

Open jaksonlima opened this issue 2 years ago • 5 comments

image

`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, }); `

jaksonlima avatar Jul 06 '22 01:07 jaksonlima

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

Flydexo avatar Jul 28 '22 10:07 Flydexo

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

Flydexo avatar Jul 28 '22 10:07 Flydexo

@kirill-konshin Is this correct ?

Flydexo avatar Jul 28 '22 10:07 Flydexo

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 avatar Jul 28 '22 18:07 DimkaSklyar

@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.

DiegoMcDipster avatar Jul 29 '22 08:07 DiegoMcDipster

Probably related to #472 😊

felix-gohla avatar Aug 19 '22 07:08 felix-gohla

@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! :)

LeshenDeaf avatar Aug 24 '22 06:08 LeshenDeaf