rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.97k stars 867 forks source link

Data not persisted when closing the app and re-opening when data is large #1046

Open jungRoit opened 5 years ago

jungRoit commented 5 years ago

When I close the app and restart it, my data are not persisted.

I am using react-native-sqlite-storage for storage with redux-offline

I am getting following error in in sqlite.core.js `warning - exception while invoking a callback: TypeError: Cannot read property 'value' of undefined `

here's my store.js

import { createOffline } from '@redux-offline/redux-offline';
import offlineConfig from '@redux-offline/redux-offline/lib/defaults';
import axios from 'axios';
import SQLite from 'react-native-sqlite-storage';
import { applyMiddleware, compose, createStore } from 'redux';
import { persistReducer, persistStore } from 'redux-persist';
import SQLiteStorage from 'redux-persist-sqlite-storage';
import { rootReducer } from './reducers';
import { getAccessToken, getTokenType } from './utils/selectors';
import { issueToken } from './global/auth';
import { loginSuccess } from './actions';
import RNFS from 'react-native-fs';
import { currentDateTime, utc } from './utils/date';

const storeEngine = SQLiteStorage(SQLite);

SQLite.DEBUG(false);
SQLite.enablePromise(true);

const {
  middleware: offlineMiddleware,
  enhanceReducer: offlineEnhanceReducer,
  enhanceStore: offlineEnhanceStore
} = createOffline({
  ...offlineConfig,
  persist: false,
  returnPromises: true,
  effect: async effect => {
    const options = {
      method: effect.method,
      url: effect.url,
      data: effect.json || effect.body,
      headers: {
        ...effect.headers
      }
    };
    // console.log('options', options);
    const request = axiosInstance(options);
    return request
      .then(response => response)
      .catch(err => {
        Promise.reject(err);
        return err;
      });
  },
  retry(_action, retries) {
    return (retries + 1) * 1000;
  }
});

const presistConfig = {
  key: 's20',
  storage: storeEngine
  // timeout: 0
};

const persistedReducer = persistReducer(presistConfig, offlineEnhanceReducer(rootReducer));

const reduxDevtool =
  (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__()) || compose;

const store = createStore(
  persistedReducer,
  {},
  compose(
    offlineEnhanceStore,
    applyMiddleware(offlineMiddleware),
    reduxDevtool
  )
);

const persistor = persistStore(store);

export { storeEngine, persistor };

export default store;

here's my App.js


import { PersistGate } from 'redux-persist/integration/react';
import { DialogProvider } from 'dialog-modal';
import store, { persistor } from './store';
import { createRootNavigator } from './Router';
import ErrorBoundary from './ErrorBoundary';

const AppContainer = createAppContainer(createRootNavigator());

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <PersistGate loading={null} persistor={persistor}>
          <ErrorBoundary>
            <DialogProvider>
              <AppContainer />
            </DialogProvider>
          </ErrorBoundary>
        </PersistGate>
      </Provider>
    );
  }
}
dkwl93 commented 4 years ago

Same issue here. Redux-offline with redux-persist v6 seems like its breaking