Skip to content

Commit 7d1922f

Browse files
committed
tweak expo updates
1 parent 68ed8ca commit 7d1922f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

apps/app/src/lib/hooks/useCheckExpoUpdates.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,32 @@ import { AppState, type AppStateStatus } from "react-native"
55

66
import { IS_DEV } from "../config"
77

8+
const TIMEOUT_KEY = "TIMEOUT"
89
export function useCheckExpoUpdates() {
910
const [isDoneChecking, setIsDoneChecking] = React.useState(false)
1011
const appState = React.useRef(AppState.currentState)
1112

12-
const checkForExpoUpdates = React.useCallback(async () => {
13+
const checkForExpoUpdates = async () => {
1314
try {
1415
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+
})
1820
const { isAvailable } = await Promise.race([Updates.checkForUpdateAsync(), timeoutRace])
21+
if (timeout) clearTimeout(timeout)
1922
if (isAvailable) {
2023
await Updates.fetchUpdateAsync()
2124
await Updates.reloadAsync()
2225
}
2326
} catch (error) {
24-
console.log("expo update timeout reached")
27+
if (!(error instanceof Error)) return
28+
if (error.message === TIMEOUT_KEY) return
2529
Sentry.captureException(error)
2630
} finally {
2731
setIsDoneChecking(true)
2832
}
29-
}, [])
33+
}
3034

3135
const handleAppStateChange = React.useCallback(
3236
(nextAppState: AppStateStatus) => {

0 commit comments

Comments
 (0)