Skip to content

Commit 2ba94d9

Browse files
fix: Linting issues and use inBrowser check for requestIdleCallback
1 parent 45e953d commit 2ba94d9

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/index.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import prefetch from './prefetch'
2-
import { canPrefetch, supportIntersectionObserver } from './utils'
2+
import { canPrefetch, supportIntersectionObserver, inBrowser } from './utils'
33

44
function installRouterPrefetch(Vue, { componentName = 'RouterLink' } = {}) {
55
const observer =
@@ -12,17 +12,18 @@ function installRouterPrefetch(Vue, { componentName = 'RouterLink' } = {}) {
1212
})
1313
})
1414

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)
2627
}
2728

2829
const RouterLink = Vue.component('RouterLink') || Vue.component('router-link')
@@ -47,7 +48,7 @@ function installRouterPrefetch(Vue, { componentName = 'RouterLink' } = {}) {
4748
},
4849
mounted() {
4950
if (this.prefetch && observer && canPrefetch) {
50-
requestIdleCallback(this.observe, { timeout: 1000 });
51+
requestIdleCallback(this.observe, { timeout: 1000 })
5152
}
5253
},
5354
beforeDestory() {

0 commit comments

Comments
 (0)