Skip to content

Commit 521e8cd

Browse files
committed
fix #352: check if navigator is present
1 parent f9f3055 commit 521e8cd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/react/xr/src/hooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function useSessionModeSupported(mode: XRSessionMode, onError?: (error: a
7171
return [
7272
(onChange: () => void) => {
7373
let canceled = false
74-
if (navigator.xr == null) {
74+
if (typeof navigator === 'undefined' || navigator.xr == null) {
7575
sessionSupported = false
7676
return () => {}
7777
}

packages/xr/src/store.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ const baseInitialState: Omit<
284284
}
285285

286286
function startEmulate(emulate: EmulatorType | true, alert: boolean) {
287+
if (typeof navigator === 'undefined') {
288+
return
289+
}
287290
Promise.all([navigator.xr?.isSessionSupported('immersive-vr'), navigator.xr?.isSessionSupported('immersive-ar')])
288291
.then(([vr, ar]) => (!ar && !vr ? import('./emulate.js') : undefined))
289292
.then((pkg) => {
@@ -560,7 +563,7 @@ async function enterXR(
560563
options: XRStoreOptions<XRElementImplementations> | undefined,
561564
xrManager: WebXRManager | undefined,
562565
): Promise<XRSession | undefined> {
563-
if (navigator.xr == null) {
566+
if (typeof navigator === 'undefined' || navigator.xr == null) {
564567
return Promise.reject(new Error(`WebXR not supported`))
565568
}
566569
if (xrManager == null) {
@@ -601,7 +604,7 @@ function setupSessionGrantedListener(
601604
enterGrantedSession: XRStoreOptions<XRElementImplementations>['enterGrantedSession'] = allSessionModes,
602605
enterXR: (mode: XRSessionMode) => void,
603606
) {
604-
if (enterGrantedSession === false) {
607+
if (typeof navigator === 'undefined' || enterGrantedSession === false) {
605608
return
606609
}
607610
if (enterGrantedSession === true) {

0 commit comments

Comments
 (0)