Skip to content

Commit 381dbe2

Browse files
authored
fix: check if the document global exists before usage (#817)
1 parent 126790b commit 381dbe2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/core/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ export function deepIncludes(a: any, b: any): boolean {
9090
}
9191

9292
export function isDocumentVisible(): boolean {
93-
const visibilityState = document?.visibilityState as any
94-
95-
return [undefined, 'visible', 'prerender'].includes(visibilityState)
93+
// document global can be unavailable in react native
94+
if (typeof document === 'undefined') {
95+
return true
96+
}
97+
return [undefined, 'visible', 'prerender'].includes(document.visibilityState)
9698
}
9799

98100
export function isOnline(): boolean {

0 commit comments

Comments
 (0)