PersistedQueryClientProvider causing UI freeze in react native #10009
Replies: 3 comments 6 replies
-
|
hard to say without a runnable reproduction |
Beta Was this translation helpful? Give feedback.
-
|
This is a common performance bottleneck in React Native when using AsyncStorage with TanStack Query. The 2-3 second UI freeze happens because AsyncStorage is relatively slow, and once the data is retrieved, the JavaScript thread has to synchronously parse a potentially large JSON string of your cache, which blocks the UI. Here are the most effective ways to solve this, ranked from the "Proper Fix" to optimization steps.
If this switch to MMKV helps unfreeze your UI and navigation, please consider marking this as the accepted answer so it can help other Expo/React Native developers! |
Beta Was this translation helpful? Give feedback.
-
|
the UI freeze happens because AsyncStorage is slow and blocks the main thread during hydration. few things to try:
pnpm add react-native-mmkvimport { MMKV } from "react-native-mmkv"
const storage = new MMKV()
const mmkvPersister = {
setItem: (key, value) => storage.set(key, value),
getItem: key => storage.getString(key) ?? null,
removeItem: key => storage.delete(key),
}
useEffect(() => {
InteractionManager.runAfterInteractions(() => {
// start hydration here
})
}, [])
const ALLOWED_QUERY_KEYS = ["agent", "users", "settings"]
{isHydrated ? children : <SplashScreen />}MMKV is the best fix, its synchronous and much faster than AsyncStorage |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I have been trying to implement query persistence in my react native app made with expo.
The issue I am facing is that the UI freezes for 2 to 3 seconds when user opens the app and it blocks the navigation as well.
This is my HOC for the persistence provider:
Beta Was this translation helpful? Give feedback.
All reactions