fix(vue-app): clear idle callback (#6430)

This commit is contained in:
Pim 2019-09-18 10:54:17 +02:00 committed by Pooya Parsa
parent 2d0f28fa75
commit 3b9eddc223

View File

@ -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()