redux-persist icon indicating copy to clipboard operation
redux-persist copied to clipboard

Persist Gate loading time

Open Florent75 opened this issue 4 years ago • 6 comments

Hi,

Here is my context :

  • "redux-persist": "^5.10.0"

  • App.js : Provider store={Store} PersistGate persistor={persistor} ... /PersistGate /Provider

  • At startup, I come from a state where there is nothing stored in redux (data have been deleted)

My app is taking 5 s on cold start, Just to go from App.js to the "initialRouteName" configured in navigation.js.

If I remove :

  •     <PersistGate persistor={persistor}>
    
  •     </PersistGate>
    

My App is taking 100 ms on cold start.

Is it some kind of a regular behaviour ? How can I decrease this startup time ?

Florent75 avatar Mar 13 '20 15:03 Florent75

Sounds like you are hitting the default timeout (which is 5s), see https://github.com/rt2zz/redux-persist/blob/master/src/persistReducer.js#L24

holmberd avatar Mar 21 '20 16:03 holmberd

Hi Holmberd,

Thanks a lot for this link, you are perfectly right. If I set the timeout to 1000, it does startup in 1000ms.

I am still wondering what timeout I shoud put, and moreover, is my redux well persisted if I set a timeout of 1ms (which seem "quite" fast) ?

Thanks

Florent75 avatar Mar 23 '20 07:03 Florent75

I would also like to know how we can optimize this

hirbod avatar May 10 '20 19:05 hirbod

Do you still have the problem? @Florent75 @Hirbod

I read the code here: https://github.com/rt2zz/redux-persist/blob/master/src/persistReducer.js#L89 that if the timeout is reached the previous state could not be restored and is empty. This read error silently fails...

voxspox avatar Jul 09 '20 13:07 voxspox

Hey Guys I have the 5s issue as well, unfortunately both links #L27 and #L89 are 404ing :(

Update: Found it: const persistConfig = { timeout: 1000, key: "root", storage: AsyncStorage, // stateReconciler: autoMergeLevel2, };

ArisPapaiakovou avatar Jan 09 '22 13:01 ArisPapaiakovou

Hey Guys I have the 5s issue as well, unfortunately both links #L27 and #L89 are 404ing :(

Update: Found it: const persistConfig = { timeout: 1000, key: "root", storage: AsyncStorage, // stateReconciler: autoMergeLevel2, };

Thanks a lot @ArisPapaiakovou! I was having the same 5s issue. It took me a long time just to understand that the issue is coming from a default timeout setting on Persist Gate loading. This "config" workaround should be included in the docs for sure.

HAZberi avatar Feb 22 '22 18:02 HAZberi