mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
fix(vue-app): clear idle callback (#6430)
This commit is contained in:
parent
2d0f28fa75
commit
3b9eddc223
@ -10,6 +10,11 @@ const requestIdleCallback = window.requestIdleCallback ||
|
||||
})
|
||||
}, 1)
|
||||
}
|
||||
|
||||
const cancelIdleCallback = window.cancelIdleCallback || function (id) {
|
||||
clearTimeout(id)
|
||||
}
|
||||
|
||||
const observer = window.IntersectionObserver && new window.IntersectionObserver((entries) => {
|
||||
entries.forEach(({ intersectionRatio, target: link }) => {
|
||||
if (intersectionRatio <= 0) {
|
||||
@ -35,10 +40,12 @@ export default {
|
||||
},
|
||||
mounted () {
|
||||
if (!this.noPrefetch) {
|
||||
requestIdleCallback(this.observe, { timeout: 2e3 })
|
||||
this.handleId = requestIdleCallback(this.observe, { timeout: 2e3 })
|
||||
}
|
||||
},
|
||||
beforeDestroy () {
|
||||
cancelIdleCallback(this.handleId)
|
||||
|
||||
if (this.__observed) {
|
||||
observer.unobserve(this.$el)
|
||||
delete this.$el.__prefetch
|
||||
@ -78,7 +85,7 @@ export default {
|
||||
if (!this.canPrefetch()) {
|
||||
return
|
||||
}
|
||||
// Stop obersing this link (in case of internet connection changes)
|
||||
// Stop observing this link (in case of internet connection changes)
|
||||
observer.unobserve(this.$el)
|
||||
const Components = this.getPrefetchComponents()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user