File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,8 @@ export default function usePrefetch(options: VisitOptions = {}) {
7
7
const isPrefetching = writable ( false )
8
8
const lastUpdatedAt = writable < number | null > ( null )
9
9
10
- const cached = router . getCached ( window . location . pathname , options )
11
- const inFlight = router . getPrefetching ( window . location . pathname , options )
10
+ const cached = typeof window === 'undefined' ? null : router . getCached ( window . location . pathname , options )
11
+ const inFlight = typeof window === 'undefined' ? null : router . getPrefetching ( window . location . pathname , options )
12
12
13
13
isPrefetched . set ( cached !== null )
14
14
isPrefetching . set ( inFlight !== null )
@@ -33,8 +33,13 @@ export default function usePrefetch(options: VisitOptions = {}) {
33
33
} )
34
34
35
35
onDestroy ( ( ) => {
36
- removePrefetchedListener ( )
37
- removePrefetchingListener ( )
36
+ if ( removePrefetchedListener ) {
37
+ removePrefetchedListener ( )
38
+ }
39
+
40
+ if ( removePrefetchingListener ) {
41
+ removePrefetchingListener ( )
42
+ }
38
43
} )
39
44
40
45
return {
You can’t perform that action at this time.
0 commit comments