@@ -5,28 +5,32 @@ import { AppState, type AppStateStatus } from "react-native"
5
5
6
6
import { IS_DEV } from "../config"
7
7
8
+ const TIMEOUT_KEY = "TIMEOUT"
8
9
export function useCheckExpoUpdates ( ) {
9
10
const [ isDoneChecking , setIsDoneChecking ] = React . useState ( false )
10
11
const appState = React . useRef ( AppState . currentState )
11
12
12
- const checkForExpoUpdates = React . useCallback ( async ( ) => {
13
+ const checkForExpoUpdates = async ( ) => {
13
14
try {
14
15
if ( IS_DEV ) return setIsDoneChecking ( true )
15
- const timeoutRace : Promise < never > = new Promise ( ( _ , reject ) =>
16
- setTimeout ( ( ) => reject ( "Expo update timeout of 10s reached" ) , 10000 ) ,
17
- )
16
+ let timeout : NodeJS . Timeout | undefined
17
+ const timeoutRace : Promise < never > = new Promise ( ( _ , reject ) => {
18
+ timeout = setTimeout ( ( ) => reject ( new Error ( TIMEOUT_KEY ) ) , 10000 )
19
+ } )
18
20
const { isAvailable } = await Promise . race ( [ Updates . checkForUpdateAsync ( ) , timeoutRace ] )
21
+ if ( timeout ) clearTimeout ( timeout )
19
22
if ( isAvailable ) {
20
23
await Updates . fetchUpdateAsync ( )
21
24
await Updates . reloadAsync ( )
22
25
}
23
26
} catch ( error ) {
24
- console . log ( "expo update timeout reached" )
27
+ if ( ! ( error instanceof Error ) ) return
28
+ if ( error . message === TIMEOUT_KEY ) return
25
29
Sentry . captureException ( error )
26
30
} finally {
27
31
setIsDoneChecking ( true )
28
32
}
29
- } , [ ] )
33
+ }
30
34
31
35
const handleAppStateChange = React . useCallback (
32
36
( nextAppState : AppStateStatus ) => {
0 commit comments