Skip to content

Commit ecb4a23

Browse files
authored
fix: prevent access to window in SSR environment (#900)
Fixes https://sendbird.atlassian.net/browse/SBISSUE-14287 The change is originally made by @AaronJamesKing notice-co@e393069
1 parent 3938524 commit ecb4a23

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/lib/hooks/useOnlineStatus.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import { uuidv4 } from '../../utils/uuid';
66
import { LoggerInterface } from '../Logger';
77

88
function useOnlineStatus(sdk: SendbirdChat, logger: LoggerInterface) {
9-
const [isOnline, setIsOnline] = useState(window?.navigator?.onLine ?? true);
9+
const [isOnline, setIsOnline] = useState(
10+
// window is undefined in SSR env
11+
typeof window !== 'undefined'
12+
? (window?.navigator?.onLine ?? true)
13+
: true,
14+
);
1015

1116
useEffect(() => {
1217
const uniqueHandlerId = uuidv4();

0 commit comments

Comments
 (0)