Skip to content

Commit 468ebbd

Browse files
authored
perf(nuxt): unsubscribe from asyncData watch when unmounted (#26821)
1 parent 6d7a558 commit 468ebbd

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎packages/nuxt/src/app/composables/asyncData.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ export function useAsyncData<
375375
const hasScope = getCurrentScope()
376376
if (options.watch) {
377377
const unsub = watch(options.watch, () => asyncData.refresh())
378-
if (hasScope) {
378+
if (instance) {
379+
onUnmounted(unsub)
380+
} else if (hasScope) {
379381
onScopeDispose(unsub)
380382
}
381383
}
@@ -384,7 +386,9 @@ export function useAsyncData<
384386
await asyncData.refresh()
385387
}
386388
})
387-
if (hasScope) {
389+
if (instance) {
390+
onUnmounted(off)
391+
} else if (hasScope) {
388392
onScopeDispose(off)
389393
}
390394
}

0 commit comments

Comments
 (0)