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 = {}) {
77 const isPrefetching = writable ( false )
88 const lastUpdatedAt = writable < number | null > ( null )
99
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 )
1212
1313 isPrefetched . set ( cached !== null )
1414 isPrefetching . set ( inFlight !== null )
@@ -33,8 +33,13 @@ export default function usePrefetch(options: VisitOptions = {}) {
3333 } )
3434
3535 onDestroy ( ( ) => {
36- removePrefetchedListener ( )
37- removePrefetchingListener ( )
36+ if ( removePrefetchedListener ) {
37+ removePrefetchedListener ( )
38+ }
39+
40+ if ( removePrefetchingListener ) {
41+ removePrefetchingListener ( )
42+ }
3843 } )
3944
4045 return {
You can’t perform that action at this time.
0 commit comments