perf(nuxt): unsubscribe from asyncData watch when unmounted (#26821)

This commit is contained in:
Danila Rodichkin 2024-04-17 15:57:45 +03:00 committed by GitHub
parent 6d7a558c69
commit 468ebbdf0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -375,7 +375,9 @@ export function useAsyncData<
const hasScope = getCurrentScope()
if (options.watch) {
const unsub = watch(options.watch, () => asyncData.refresh())
if (hasScope) {
if (instance) {
onUnmounted(unsub)
} else if (hasScope) {
onScopeDispose(unsub)
}
}
@ -384,7 +386,9 @@ export function useAsyncData<
await asyncData.refresh()
}
})
if (hasScope) {
if (instance) {
onUnmounted(off)
} else if (hasScope) {
onScopeDispose(off)
}
}