1
1
import prefetch from './prefetch'
2
- import { canPrefetch , supportIntersectionObserver } from './utils'
2
+ import { canPrefetch , supportIntersectionObserver , inBrowser } from './utils'
3
3
4
4
function installRouterPrefetch ( Vue , { componentName = 'RouterLink' } = { } ) {
5
5
const observer =
@@ -12,17 +12,18 @@ function installRouterPrefetch(Vue, { componentName = 'RouterLink' } = {}) {
12
12
} )
13
13
} )
14
14
15
- const requestIdleCallback = window . requestIdleCallback ||
16
- function ( cb ) {
17
- const start = Date . now ( )
18
- return setTimeout ( function ( ) {
19
- cb ( {
20
- didTimeout : false ,
21
- timeRemaining : function ( ) {
22
- return Math . max ( 0 , 50 - ( Date . now ( ) - start ) )
23
- } ,
24
- } )
25
- } , 1 )
15
+ const requestIdleCallback =
16
+ ( inBrowser && window . requestIdleCallback ) ||
17
+ function ( cb ) {
18
+ const start = Date . now ( )
19
+ return setTimeout ( ( ) => {
20
+ cb ( {
21
+ didTimeout : false ,
22
+ timeRemaining ( ) {
23
+ return Math . max ( 0 , 50 - ( Date . now ( ) - start ) )
24
+ }
25
+ } )
26
+ } , 1 )
26
27
}
27
28
28
29
const RouterLink = Vue . component ( 'RouterLink' ) || Vue . component ( 'router-link' )
@@ -47,7 +48,7 @@ function installRouterPrefetch(Vue, { componentName = 'RouterLink' } = {}) {
47
48
} ,
48
49
mounted ( ) {
49
50
if ( this . prefetch && observer && canPrefetch ) {
50
- requestIdleCallback ( this . observe , { timeout : 1000 } ) ;
51
+ requestIdleCallback ( this . observe , { timeout : 1000 } )
51
52
}
52
53
} ,
53
54
beforeDestory ( ) {
0 commit comments