13
13
import { AriaLabelingProps , DOMAttributes , FocusableElement } from '@react-types/shared' ;
14
14
import { MutableRefObject , useCallback , useEffect , useState } from 'react' ;
15
15
import { useLayoutEffect } from '@react-aria/utils' ;
16
- import { useSyncExternalStore } from 'use-sync-external-store/shim' ;
16
+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js ' ;
17
17
18
18
export type AriaLandmarkRole = 'main' | 'region' | 'search' | 'navigation' | 'form' | 'banner' | 'contentinfo' | 'complementary' ;
19
19
@@ -85,7 +85,11 @@ function subscribe(fn: () => void) {
85
85
return ( ) => document . removeEventListener ( 'react-aria-landmark-manager-change' , fn ) ;
86
86
}
87
87
88
- function getLandmarkManager ( ) : LandmarkManagerApi {
88
+ function getLandmarkManager ( ) : LandmarkManagerApi | null {
89
+ if ( typeof document === 'undefined' ) {
90
+ return null ;
91
+ }
92
+
89
93
// Reuse an existing instance if it has the same or greater version.
90
94
let instance = document [ landmarkSymbol ] ;
91
95
if ( instance && instance . version >= LANDMARK_API_VERSION ) {
@@ -100,8 +104,8 @@ function getLandmarkManager(): LandmarkManagerApi {
100
104
}
101
105
102
106
// Subscribes a React component to the current landmark manager instance.
103
- function useLandmarkManager ( ) : LandmarkManagerApi {
104
- return useSyncExternalStore ( subscribe , getLandmarkManager ) ;
107
+ function useLandmarkManager ( ) : LandmarkManagerApi | null {
108
+ return useSyncExternalStore ( subscribe , getLandmarkManager , getLandmarkManager ) ;
105
109
}
106
110
107
111
class LandmarkManager implements LandmarkManagerApi {
0 commit comments