Skip to content

Commit 76226a7

Browse files
authored
bugfix: persist not working on iOS (#836)
`createPersistor` defines a `timingMethod` that won't work on iOS. The `timingMethod` utilizes `requestIdleCallback` if it is defined. It turns out that the pollyfilled requestIdleCallback for RN on iOS, requires a second parameter with a specific timeout - where as the native implementation does not. Setting the specific parameter invokes this function across all platforms.
1 parent 0b16f86 commit 76226a7

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easy-peasy",
3-
"version": "6.0.0",
3+
"version": "6.0.1",
44
"description": "Vegetarian friendly state for React",
55
"license": "MIT",
66
"main": "dist/index.cjs.js",

src/persistence.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ function createStorageWrapper(storage, transformers = [], migrations = {}) {
7676
: data;
7777

7878
const hasMigrations = Object.keys(migrations).length > 0;
79-
const result = hasMigrations ? migrate(storageData, migrations) : storageData;
79+
const result = hasMigrations
80+
? migrate(storageData, migrations)
81+
: storageData;
8082

8183
if (
8284
outTransformers.length > 0 &&
@@ -173,7 +175,9 @@ export function createPersistor(persistKey, _r) {
173175
typeof window === 'undefined'
174176
? (fn) => fn()
175177
: window.requestIdleCallback != null
176-
? window.requestIdleCallback
178+
? // We need to wrap requestIdleCallback, because it doesn't work without
179+
// a second parameter on iOS with ReactNative
180+
(fn) => window.requestIdleCallback(fn, { timeout: 0 })
177181
: window.requestAnimationFrame;
178182

179183
const persist = (nextState) => {

website/docs/docs/recipes/connecting-to-reactotron.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ Then update the manner in which you create your Easy Peasy store.
3030
import { createStore } from 'easy-peasy';
3131
import model from './model';
3232

33-
// There might be an issue causing `setItem` not being called correctly
34-
// for iOS devices using React Native. The solution for this is currently
35-
// to remove the implemenation of `requestIdleCallback`.
36-
// Read this issue for more information: https://github.com/ctrlplusb/easy-peasy/issues/599
37-
window.requestIdleCallback = null;
38-
3933
let storeEnhancers = [];
4034

4135
if (__DEV__) {

0 commit comments

Comments
 (0)