Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist doesnt work with react-native-async-storage/async-storage #694

Closed
OsapBender opened this issue Aug 29, 2021 · 9 comments · Fixed by #836
Closed

Persist doesnt work with react-native-async-storage/async-storage #694

OsapBender opened this issue Aug 29, 2021 · 9 comments · Fixed by #836
Labels
bug Something isn't working

Comments

@OsapBender
Copy link

OsapBender commented Aug 29, 2021

Today I upgraded easy-peasy from v3.3.1 to v5.0.3 and my async store doesnt work anymore.
I have persistor

import AsyncStorage from '@react-native-async-storage/async-storage';

import {persist} from 'easy-peasy';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export default (reducer) =>
  persist(reducer, {
    storage: {
      async getItem(key) {
        return JSON.parse(await AsyncStorage.getItem(key));
      },
      setItem(key, data) {
        const jsonValue = JSON.stringify(data);
        console.log('key2: ', key, jsonValue);
        AsyncStorage.setItem(key, jsonValue);
      },
      removeItem(key) {
        console.log('key3: ', key);
        AsyncStorage.removeItem(key);
      },
    },
  });

on v3.3.1 my console log was like
Снимок экрана 2021-08-29 в 17 04 51

but after upgrading it looks like
Снимок экрана 2021-08-29 в 17 06 44

my store model:

import {Action, action} from 'easy-peasy';
import persistor from '../persistor';
import {keys, storeAsyncData} from '../asyncStorage';

export interface IAuthModel {
  isAuth: boolean;
  setAuth: Action<IAuthModel, boolean>;
}

const authModel: IAuthModel = {
  isAuth: false,
  setAuth: action((state, payload: boolean): void => {
    state.isAuth = payload;
  }),
};

const thunks = {};

export default persistor({
  ...authModel,
  ...thunks,
});

import AppModel, {IAppState} from './app';
import Auth from './auth';
import {IAuthModel} from './auth';

export interface IStoreModel {
  app: IAppState;
  auth: IAuthModel;
}

const storeModel: IStoreModel = {
  app: AppModel,
  auth: Auth,
};

export default storeModel;

if i downgrade easy-peasy from 5.0.3 to 3.3.1 it works fine.

What's wrong?

PS
I read that changes from 3.3.1 to 5.0.3 but cannot find a solution

@tamagokun
Copy link

Same here, tried with both v5 and v4, setItem is never being called on storage

@rpadilla6
Copy link

Confirmed I had this issue when trying to upgrade to v5, I'm stuck at v3 for this reason. If I have the luxury of bonus time over the holidays maybe I can take a look and see what's going on

@rbruels
Copy link

rbruels commented Jan 28, 2022

This may be the issue for anyone reading this -- certainly was for me after the v3 -> v5 upgrade. There is a workaround in this thread.

The root cause is this RN regression.

@ctrlplusb ctrlplusb added bug Something isn't working under-consideration labels Feb 8, 2022
@sefaokumus
Copy link

Is there any progress on this issue ?

@damassi
Copy link
Contributor

damassi commented Apr 21, 2023

FWIW, we've been using this same setup in easy-peasy@5.2 without problem. And just upgraded to v6 with no problem.

@no-stack-dub-sack
Copy link
Collaborator

Thanks @damassi! Is it possible to post a simple example of the setup that's working for you in case anyone else is blocked by this? As suggested by @rbruels the root cause may have been an RN regression issue, so I'm wondering if maybe this is fixed in newer versions (though it doesn't appear to have been addressed on the linked issue)?

@damassi
Copy link
Contributor

damassi commented May 5, 2023

Coming back to this, I realized we were already using the requestIdleCallback = null hack, and that is why things were working! so working around the regression.

@no-stack-dub-sack
Copy link
Collaborator

no-stack-dub-sack commented May 6, 2023

Thanks for checking @damassi! At least there's an acceptable workaround.

@jmyrland
Copy link
Collaborator

Coming back to this, I realized we were already using the requestIdleCallback = null hack, and that is why things were working! so working around the regression.

This is now fixed in v6.0.1, which means that the requestIdleCallback = null workaround is no longer required for easy-peasy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

9 participants