rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.94k stars 866 forks source link

Getting error redux-persist: rehydrate for "root" called after timeout #717

Closed ajaymore closed 6 years ago

ajaymore commented 6 years ago
redux-persist: rehydrate for "root" called after timeout., Object {
  "INITIALIZING": true,
  "_persist": Object {
    "rehydrated": true,
    "version": -1,
  },
  "user": null,
}, undefined
- node_modules/redux-persist/lib/persistReducer.js:92:59 in _rehydrate
- ... 13 more stack frames from framework internals

I am using expo sdk version 25 My code is as below

reducers.js

export default (
  state = {
    INITIALIZING: true,
    user: null
  },
  action
) => {
  switch (action.type) {
    default:
      return state;
  }
};

configureStore.js

import { createStore } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';

import rootReducer from './reducers';

const persistConfig = {
  key: 'root',
  storage
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

export default () => {
  let store = createStore(persistedReducer);
  let persistor = persistStore(store);
  return { store, persistor };
};

App.js

import React from 'react';
import { StyleSheet, Text, ActivityIndicator, View } from 'react-native';
import * as firebase from 'firebase';
import { PersistGate } from 'redux-persist/integration/react';
import { firebaseConfig } from './src/config';
import { Provider } from 'react-redux';
import configureStore from './src/configureStore';
import styled from 'styled-components';
// import Main from './src/screens/Main';
const { store, persistor } = configureStore();
firebase.initializeApp(firebaseConfig);

const StyledLoaderContainer = styled.View`
  justify-content: center;
  align-items: center;
  margin-top: 100px;
`;

const Loading = () => (
  <StyledLoaderContainer>
    <ActivityIndicator />
    <Text>Initializing...</Text>
  </StyledLoaderContainer>
);

export default class App extends React.Component {
  render() {
    return (
      <Provider store={store}>
        <PersistGate loading={<Loading />} persistor={persistor}>
          <View>
            <Text>This is root</Text>
          </View>
        </PersistGate>
      </Provider>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center'
  }
});
leonchabbey commented 6 years ago

Same here.

Seems related to these recent commits: https://github.com/rt2zz/redux-persist/commit/436050044d5ea6483d084c67820cd3fd9466eb38 and https://github.com/rt2zz/redux-persist/commit/98a78d9aa39d6634a39bd81c776d3ce91e0e7192

JanithaR commented 6 years ago

The same happens to me after upgrading to v5.7.1

Amurmurmur commented 6 years ago

Same story here :/

ghost commented 6 years ago

I just downgraded version to 5.6.12 and still not working

NicholasBertazzonAga commented 6 years ago

@avid21 Reverting back to 5.6.12 worked for me.

JanithaR commented 6 years ago

How to downgrade? Uninstall and re-install?

krzysztof-miemiec commented 6 years ago

Use semver ~5.6.0 instead of ^5.6.0. I forgot about it at first.

ghost commented 6 years ago

@NichAga Yes, it should work. I was using Remote JS debugging. I stopped it and hence naturally it's working now.

NicholasBertazzonAga commented 6 years ago

@JanithaR npm install redux-persist@5.6.12 @avid21 good :D

diegorodriguesvieira commented 6 years ago

Same here! =(

JanithaR commented 6 years ago

Thanks @NichAga I figured it out. Just downgrade and keep working for the moment guys.

rohanx96 commented 6 years ago

Yes, getting the same error. Reverting to 5.6.12 worked

l3lackcurtains commented 6 years ago

Worked after switching back to redux-persist@5.6.12

outaTiME commented 6 years ago

Same 😡

jarvisluong commented 6 years ago

Switch back to 5.6.12 works!

outaTiME commented 6 years ago

@jarvisluong yup im switch back to ~5.6.0

rt2zz commented 6 years ago

apologize for the churn here, v5.7.2 resolves the issue.

tests missed the issue on 5.7.1 as it was a console.error, not an actual exception

RodolfoSilva commented 6 years ago

@rt2zz I still have the same error after update to v5.7.2.

sytolk commented 6 years ago

I don't have this error with v.5.7.2. @RodolfoSilva are you sure that you upgrade version? You can check this in npm.lock or yarn.lock file.

RodolfoSilva commented 6 years ago

@sytolk, Yes, I'm use the latest version and still have the error. This error only happens when I use the debug in the first time.

"redux-persist": {
      "version": "5.7.2",
      "resolved": "https://registry.npmjs.org/redux-persist/-/redux-persist-5.7.2.tgz",
      "integrity": "sha512-NgkSoPA3o6vAo09U5hnzO8CgHNhnBIcZyZBr+tRa/pDDeQqtcsP/zru9b2vz5tIpK6GCYGEsEjSzWUU/vxfRQA=="
    },
ajaymore commented 6 years ago

I can confirm it's working with 5.7.2.

patlux commented 6 years ago

For me it was the short 'debounce' time which caused the error:

const persistOptions = {
  storage,
  debounce: 100, // <-- not working in 'Debug JS' mode
  key: DeviceInfo.getBundleId(),
  transforms: [compressor],
};

persistReducer(persistOptions, rootReducer)

I increased the time to 500 and now it's working fine.

react-native: v0.53.0 redux-persist: 5.9.1


Ok, that fixed not the error. I downgraded to v5.7.2 v5.6.12 and now it's working.

challme28 commented 6 years ago

I have to say I've been stuck in this problem for a while now and it was my fault. I forgot to return an action on an Epic. I hope this helps anyone

calanti commented 6 years ago

I am stuck with this issue on my recently expo detached project. My state is never persisted regardless of remote debugging, and occasionally I get the error like the OP.

Expo: 24.0.0 react: 16.0.0 RN: Expo 24.0.0 fork react-redux: 5.0.7 redux: 3.7.2 redux-persist: 5.9.1

On an up note, thank you very much for your work!

droegier commented 6 years ago

Same as @calanti

"expo": "25.0.0",
"native-base": "2.3.1",
"react": "16.2.0",
"react-native": "0.52.0",
"react-navigation": "^1.4.0",
"react-redux": "5.0.7",
"redux": "3.7.2",
"redux-persist": "5.9.1"
kapobajza commented 6 years ago

I was getting the same error on redux-persist version 5.9.1.

It was working fine until I put the whitelist prop into rootPersistConfig:

const rootPersistConfig = { key: 'root', ... , whitelist: ['auth'] };

But then I switched back to using the blacklist property and everything works fine now.

const rootPersistConfig = { key: 'root', ... , blacklist: ['navigation', 'isLoading', 'hasErrored'] };

calanti commented 6 years ago

Thanks for the insight and yes I am whitelisting, but blacklisting is not really a maintainable solution for me, too many recuders and I only need 2 whitelisted. Hopefully this can help the devs identify the issue though!

baba43 commented 6 years ago

I have just created a new project with Expo and can not get this work either.

ChristienGuy commented 6 years ago

I get this issue with 5.9.1. For me it only occurs when remote debugging.

Potentially related to this issue with setTimeout in React Native https://github.com/facebook/react-native/issues/4470

augusto-altman commented 6 years ago

Same as @ChristienGuy, only get the issue when remote debugging.

tarikhagustia commented 6 years ago

same here @ChristienGuy error when remote debugging :3

jamessawyer commented 6 years ago

some issue with redux-persist V5.9.2 when debugger is open.

seanfar commented 6 years ago

Running into this issue with redux-persist@latest on Android only (tested on API 27 and API 23). Seems to work fine on iOS.

Happens regardless of whether the debugger is attached or not, and I tried using both AsyncStorage and FilesystemStorage.

Rolling back to 5.6.12 and 5.7.2 have both yielded positive results for me, and seem to work just fine.

kenkotch commented 6 years ago

After trying a few different versions to no avail, I restarted my computer like I would have on Windows98. Everything is back to normal and working again. It's not a good solution, but may be worth a try if you are still stuck...(I was only getting the error in debug mode)

nickofthyme commented 6 years ago

Appears to be working on 5.7.2 with remote JS Debugger.

Update: Error still occurs intermittently on 5.7.2. But much less than 5.9.2.

xliank commented 6 years ago

I'm using version 5.9.1 , only show error when enable Remote JS Debugging. Still no solution?

jgfidelis commented 6 years ago

Same issue: Android with Remote debugging on 5.9.1. Will try version 5.7.2.

Edit: 5.7.2 did not work, 5.6.12 looks ok.

Dmitrylolo commented 6 years ago

same

"axios": "^0.18.0", "expo": "^27.0.2", "qs": "^6.5.2", "react": "16.3.1", "react-native": "https://github.com/expo/react-native/archive/sdk-27.0.0.tar.gz", "react-native-elements": "^0.19.1", "react-navigation": "^2.0.1", "react-redux": "^5.0.7", "redux": "^4.0.0", "redux-persist": "^5.9.1", "redux-thunk": "^2.2.0"

undefined is not an object (evaluating 'action.payload.search') search in whitelist

FMdigit commented 6 years ago

using Redux Persist version 5.9.1 ... same issue

altenorjr commented 6 years ago

5.10 idem

wmlutz commented 6 years ago

"redux-persist": "^5.9.1"

I'm having the same issues. Still no fix? Or hints? Or clues?

ilovett commented 6 years ago

@wmlutz restarting the android emulator and/or wiping the data of the device image via AVD Manager

MattJakeman commented 6 years ago

Same issue for me on 5.10.0 - It's working correctly until I switch on remote debugging.

nilscox commented 6 years ago

I also do encounter this error with redux-persist@5.10.0.

The error message I'm getting during the persist/REHYDRATE action is redux-persist: persist timed out for persist key "root".

As far as I understand, redux-persist internally uses RN's AsyncStorage in order to store the state. Also, there is an issue when using AsyncStorage when debugging remotly, which makes the promise hang indefinitely (and may cause a timeout).

Could it be the reason why redux-persist fails to load the state?

ghost commented 6 years ago

@nilscox are you using any middlewares like redux-logger? I faced the exact same issues as yours while Debugging JS remotely

  1. redux-persist was not working, threw err : persist timed out for persist key "root"
  2. AsyncStorage promises never got resolved - issue

And however when I tried to run with remote debugger it threw an error saying TypeError: undefined is not an object (evaluating self.fetch) - issue even tried to fix it based on this snippet provided here

and once I removed redux-logger the app started to behave in expected manner. Promises got resolved without timeout. Somehow made me feel all were connected! :confused:

Hope it helps someone! :raised_hands: Cheers!

ilovett commented 6 years ago

I don't necessarily think this is an issue with redux-persist -- I use React Native Debugger, which has an option to Log AsyncStorage content to console.

When I first cold boot an emulator and run the project, and start debugging remotely, I can see rehydrate works immediately for a while. During this time if I Log AsyncStorage content then it will output the content to console immediately.

Once rehydrate starts timing out, if I Log AsyncStorage content then I get nothing in my console... which makes me think this is more of an android emulator issue or asyncstorage issue...

ilovett commented 6 years ago

see: https://github.com/facebook/react-native/pull/18522

nilscox commented 6 years ago

@Arjith-Natarajan I am using redux-logger. I will investigate if removing it can solve the problem.

@ilovett this is defenetly not a redux-persist related error, but it has a side effect that makes redux-persist timeout. It happens to me on a real device on Android, so I'm pretty sure it's not related to the emulator environment.

For now, I am using this workaround. I created this tool that allow to access a storage on my computer from my device. I am using it with a networkStorage adapter that I give to redux-persist.

jjercx commented 6 years ago

For me happens debugging and on android device.

IOsonoTAN commented 6 years ago

I used "redux-persist": "^5.10.0" on Next.js, first i got the same error, i tried to not set initialState or set to object empty {} like this:

const store = createStore(persistedReducer, {})

It persisted and works fine.