rt2zz / redux-persist

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

PersistGate bootstrapped never set to true #1180

Open ajfick opened 4 years ago

ajfick commented 4 years ago

I'm currently working a react-native project and having an issue that causes my app to give a white screen and never load on open. After some debugging, I've found that it appears to be because the bootstrapped state value in my PersistGate is never set to true despite it being possible for me to see that my state was rehydrated in the redux devtools. When I manually flip the bootstrapped state value in the PersistGate to true using my react-native devtools, the app immediately loads as expected.

One thing to note, it is necessary for me in this project, to be able to insert the filter values received from Firebase messaging (notifications) into the state before the rest of the app is rendered. Which is done by the constant declaration initialStore. I'm not sure if this is the correct way to handle this with redux-persist, or if it could be the cause of the bootstrapped state value not being set to true.

function StateWrapper({ filter }) {
  const initialStore = {...initialState, item: { ...initialState.item, filter: { ...initialState.item.filter, ...filter }}};

  const store = createStore(reducer, initialStore, __DEV__ && window.__REDUX_DEVTOOLS_EXTENSION__?  compose(applyMiddleware(thunk), reduxDevTools) : compose(applyMiddleware(thunk)));

  const persistor = persistStore(store);

  return (
    <Provider store={store}>
      <PersistGate loading={null} persistor={persistor}>
          <Navigation uriPrefix="lp://" />
      </PersistGate>
    </Provider>
  );
}

I'm not sure if this is a bug or an error on my part, but not rendering anything at all doesn't seem like the intended result to me.

MrOggy85 commented 4 years ago

Same

using "redux-persist": "6.0.0"

marioklaver commented 4 years ago

Same here. But this was my own fault. I passed the rootReducer instead of the persistedReducer to the store. Hope this helps others.

sokoya commented 2 years ago

Same here, please have you found any solution to this... I am passing the persistedReducer to the store.

Below is my store; I am using redux toolkit configureStore

const store = configureStore({ reducer: persistedReducer, middleware: (getDefaultMiddleware) => getDefaultMiddleware({ serializableCheck: { ignoredActions: [FLUSH, REHYDRATE,PAUSE, PERSIST, PURGE, REGISTER] } }).concat([ unauthenticateMiddleware, apiSlice.middleware, ]), preloadedState: preloadedState, })