The __experimental_resourceCache property introduced in this guide is an experimental feature. It is subject to change in future updates, so use it cautiously in production environments. Ensure thorough testing and stay informed through the package's changelog.
The Clerk Expo SDK provides enhanced offline support to improve reliability and user experience. This update enables your app to bootstrap offline using cached Clerk resources, ensuring quick initialization without requiring an internet connection.
It offers the following benefits:
Initialization of the Clerk SDK is now more resilient to network failures.
Faster resolution of the isLoaded property and the <ClerkLoaded> control component with only a single network fetch attempt. If the fetch fails, it gracefully falls back to cached resources.
Network errors are no longer muted, allowing developers to catch and handle them effectively in their custom flows.
The getToken()JavaScript Icon function in the useAuth() hook now supports returning cached tokens, minimizing disruptions caused by network failures.
When there is no internet connection, Clerk's custom flows (e.g., signIn.create()) will throw a network error.
To handle network errors in your Expo app, you can use the isClerkRuntimeError() function to check if the error is a Clerk-related error. Clerk-related errors are returned as an array of ClerkAPIErrorJavaScript Icon objects. These errors contain a code property that you can use to identify the specific error. See the following example.
import { useSignIn, isClerkRuntimeError } from'@clerk/clerk-expo'import { Link, useRouter } from'expo-router'import { Text, TextInput, Button, View } from'react-native'import React from'react'exportdefaultfunctionSignInPage() {const { signIn,setActive,isLoaded } =useSignIn()constrouter=useRouter()const [emailAddress,setEmailAddress] =React.useState('')const [password,setPassword] =React.useState('')constonSignInPress=React.useCallback(async () => {if (!isLoaded) returntry {constsignInAttempt=awaitsignIn.create({ identifier: emailAddress, password, })// The rest of your custom flow logic } catch (err) {// See https://clerk.com/docs/custom-flows/error-handling// for more info on error handlingif (isClerkRuntimeError(err) &&err.code ==='network_error') {console.error('Network error occurred!') }console.error(JSON.stringify(err,null,2)) } }, [isLoaded, emailAddress, password])return ( <View> <Buttontitle="Sign in"onPress={onSignInPress} /> </View> )}