redux-persist: redux-persist: persist timed out for persist key "root" at eval
^ In this screenshot, my config key is ‘tf’ because I’ve been trying to debug this error, lol. But yeah, I only see this error in the redux logs for the persist/REHYDRATE action. It doesn’t seem to be affecting the actual desired behavior of redux-persist, and I can’t figure out why it’s being thrown and how to get rid of it. I dug through the source and looks like @rt2zz fixed something in February that’s nearby but not exactly the same thing. This error seemed to pop up out of nowhere for us.
Here’s my setup. I wrote most of this originally pre-v5, then migrated to 5.0.0-proto and have been on that version since just now. This error happens for me both on 5.0.0-proto and after upgrading to 5.9.1.
Looking at the migration guide now makes me think some things aren’t quite right in my code, even if those things are not connected to this error. I’m using getStoredState & persistStore differently. Hopefully someone can give some insight 🙏 .
store.js
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import { persistStore, persistReducer, getStoredState } from 'redux-persist';
import localforage from 'localforage';
import { toNumber } from 'lodash';
const middlewareList = [
....
];
if ( DEBUG ) {
middlewareList.push(createLogger());
}
const config = {
key: 'root',
storage: localforage,
debug: true,
whitelist: ['activity', 'user']
};
const reducer = persistReducer(config, rootReducer);
const createStoreWithMiddleware = applyMiddleware(...middlewareList)(createStore);
const createRehydratedStore = (renderApp) => {
getStoredState(config)
.then((restoredState) => {
const version = APP_VERSION; // eslint-disable-line no-undef
const SCOPE_VERSION_LOCAL_STORAGE_KEY = 'scope-version';
const savedVersion = window.localStorage.getItem(SCOPE_VERSION_LOCAL_STORAGE_KEY);
const newVersion = toNumber(savedVersion) !== toNumber(version);
const storeState = newVersion ? {} : restoredState;
const store = createStoreWithMiddleware(reducer, storeState);
const persistor = persistStore(store);
if ( !savedVersion ) {
window.localStorage.setItem(SCOPE_VERSION_LOCAL_STORAGE_KEY, version);
} else if ( newVersion ) {
persistor.purge();
window.localStorage.setItem(SCOPE_VERSION_LOCAL_STORAGE_KEY, version);
}
renderApp(store, persistor);
});
};
export default createRehydratedStore;
Note: we’re trying to do some manual cache invalidation up there by passing an empty obj to createStore if there’s a new app version. Maybe there’s a better way to do this. I wrote it back on 5.0.0-proto, and looking at it again I’m not sure why we needed to both a) pass an empty obj and b) call persistor.purge.
app.js, which calls createRehydratedStore and gets the app rendered
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import { withRouter } from 'react-router';
import createStore from './store';
import { PersistGate } from 'redux-persist/integration/react';
import App from 'views/app';
const AppWithRouter = withRouter(App);
const renderApp = (store, persistor) => {
render((
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<BrowserRouter>
<AppWithRouter />
</BrowserRouter>
</PersistGate>
</Provider>
), document.getElementById('root'));
};
createStore(renderApp);
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 20
- Comments: 24
setTimeout is started in
persistReducermethod, but I did not found clearTimeout… Here: https://github.com/rt2zz/redux-persist/commit/436050044d5ea6483d084c67820cd3fd9466eb38#diff-78c77d9b1c28b6777a1c3ec40164bb64R83So, I just disabled timeout in my configs
I ran into this issue a couple of hours ago. Now everything is perfectly fine. In the hopes of helping what happened in my case here it is.
I was working in the project and when ran outta battery in my mac so I just closed it and set aside yesterday. Today I just resumed working. And I remember the Android time mismatch warning was visible on my emulator. So lazy me just changed the clock setting and continued to work and that’s when the issue popped up and I found this issue. I just ignored for the time being and kept working and when tired just shutdown my mac.
Now again I started working everything fresh and the issue is no longer there. So I guess just restart app, emulator, bundler or PC and it’ll just go away.
Can you take a look at this issue? It happened two years
Upon further investigation looks like state is persisted only after timeout action is fired. Then persisted state is updated with changes in redux, but after page reload it gets reset to initialState after timeout again.
Using react-boilerplate with switched off injected reducers and sagas and root Reducer state converted to simple object with Immutable in branches.
Setup is the same as in the documentation.
Could you please advise, @rt2zz ?
Just to be clear, I’m not affiliated with this project in any way, I was just observing that this package is clearly abandoned given the lack of activity.
Still happening now too, The
timeout: nullis just removing the crash from happening but I got some weird behavior in the app, At some point i get an old state just after updating some data.I had to set the
timeoutproperty to1.0andnulldidn’t work. Is it really expected that every time you call persistStore for the first time, it times out because it can’t find the root key?Update from me @sinkovsky - I noticed it’s the size of my
restoredStatethat I pass as a second argument tocreateStoreWithMiddlewarethat affects whether or not this timeout error is thrown.Looks like I’m getting the same error, but it nothing is stored in the store. Were you able to solve it?