mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-21 07:59:33 +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)
|
}, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cancelIdleCallback = window.cancelIdleCallback || function (id) {
|
||||||
|
clearTimeout(id)
|
||||||
|
}
|
||||||
|
|
||||||
const observer = window.IntersectionObserver && new window.IntersectionObserver((entries) => {
|
const observer = window.IntersectionObserver && new window.IntersectionObserver((entries) => {
|
||||||
entries.forEach(({ intersectionRatio, target: link }) => {
|
entries.forEach(({ intersectionRatio, target: link }) => {
|
||||||
if (intersectionRatio <= 0) {
|
if (intersectionRatio <= 0) {
|
||||||
@ -35,10 +40,12 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
if (!this.noPrefetch) {
|
if (!this.noPrefetch) {
|
||||||
requestIdleCallback(this.observe, { timeout: 2e3 })
|
this.handleId = requestIdleCallback(this.observe, { timeout: 2e3 })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
|
cancelIdleCallback(this.handleId)
|
||||||
|
|
||||||
if (this.__observed) {
|
if (this.__observed) {
|
||||||
observer.unobserve(this.$el)
|
observer.unobserve(this.$el)
|
||||||
delete this.$el.__prefetch
|
delete this.$el.__prefetch
|
||||||
@ -78,7 +85,7 @@ export default {
|
|||||||
if (!this.canPrefetch()) {
|
if (!this.canPrefetch()) {
|
||||||
return
|
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)
|
observer.unobserve(this.$el)
|
||||||
const Components = this.getPrefetchComponents()
|
const Components = this.getPrefetchComponents()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user