Environment:
| Library |
Version |
redux-persist |
"^6.0.0" |
@reduxjs/toolkit |
"^2.3.0" |
react-redux |
"^9.1.2" |
react |
"19.2.0" |
Description:
When using persistReducer as a nested slice (not root reducer) inside a large RTK configureStore that contains many RTK Query API reducers, and using PersistGate with persistStore(store), the app throws a stack overflow during render.
Minimal reproduction of the setup:
tabs.util.ts — persisted slice definition:
import { combineReducers } from "@reduxjs/toolkit";
import { persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import tabsReducer from "./tabs.slice";
const rootReducer = combineReducers({ tabs: tabsReducer });
const persistConfig = { key: "tabs-core", storage };
export const persistedReducer = persistReducer(persistConfig, rootReducer);
shared-common-apps-store.ts — nested inside main store:
export const sharedCommonAppsReducerStore = {
persistedReducer: persistedReducer, // ← nested persisted reducer
preservedAppIdSlice: preservedAppIdSlice.reducer,
triggerPasteReducer: triggerPasteReducer,
[personsApi.reducerPath]: personsApi.reducer,
// ... ~40 more RTK Query API reducers
};
store.ts — main store:
export const store = configureStore({
reducer: {
...sharedCommonAppsReducerStore, // contains persistedReducer as nested slice
...accountingReducerStore,
...treasuryReducerStore,
...generalReducerStore,
...sharedServiceReducerStore,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware()
.prepend(listenerMiddleware.middleware)
.concat(mergeMiddlewareStore)
.concat(rtkQueryErrorLogger),
});
SharedProviders.tsx — PersistGate usage:
export function SharedProviders({ theme, children, store }) {
const persistor = persistStore(store); // called on the main store
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
{children}
</PersistGate>
</Provider>
);
}
App.tsx — entry point:
export function App() {
const theme = useMemo(() => createSharedTheme(), []);
return (
<SharedProviders theme={theme} store={store}>
<RouterProvider router={router} />
</SharedProviders>
);
}
Error:
RangeError: Maximum call stack size exceeded
at actuallyMutateSubscriptions (chunk-JVMNWONT.js:2000:39)
at chunk-JVMNWONT.js:2089:23
at chunk-JVMNWONT.js:2717:61
at chunk-JVMNWONT.js:2720:17
at chunk-JVMNWONT.js:2720:17
... (repeating)
What I tried:
- Moving
persistStore outside of React component → same error
- Using
useRef(() => persistStore(store)) → same error
- Adding
serializableCheck ignored actions → same error
- Creating a separate store just for
persistStore → different error (PersistGate and Provider on different stores)
- Removing
persistedReducer from the store → error disappears ✅
- Removing
PersistGate → error disappears ✅
Question:
Is using persistReducer as a nested slice (not root reducer) with PersistGate on the main store a supported pattern? The error only appears when the store has a large number of reducers (~50+). With fewer reducers it seems to work fine.
If this pattern is not supported, what is the recommended approach for persisting only a subset of the Redux state?
Environment:
redux-persist"^6.0.0"@reduxjs/toolkit"^2.3.0"react-redux"^9.1.2"react"19.2.0"Description:
When using
persistReduceras a nested slice (not root reducer) inside a large RTKconfigureStorethat contains many RTK Query API reducers, and usingPersistGatewithpersistStore(store), the app throws a stack overflow during render.Minimal reproduction of the setup:
tabs.util.ts— persisted slice definition:shared-common-apps-store.ts— nested inside main store:store.ts— main store:SharedProviders.tsx—PersistGateusage:App.tsx— entry point:Error: RangeError: Maximum call stack size exceeded at actuallyMutateSubscriptions (chunk-JVMNWONT.js:2000:39) at chunk-JVMNWONT.js:2089:23 at chunk-JVMNWONT.js:2717:61 at chunk-JVMNWONT.js:2720:17 at chunk-JVMNWONT.js:2720:17 ... (repeating)What I tried:
persistStoreoutside of React component → same erroruseRef(() => persistStore(store))→ same errorserializableCheckignored actions → same errorpersistStore→ different error (PersistGateandProvideron different stores)persistedReducerfrom the store → error disappears ✅PersistGate→ error disappears ✅Question:
Is using
persistReduceras a nested slice (not root reducer) withPersistGateon the main store a supported pattern? The error only appears when the store has a large number of reducers (~50+). With fewer reducers it seems to work fine.If this pattern is not supported, what is the recommended approach for persisting only a subset of the Redux state?