Skip to content

Commit

Permalink
perf(nuxt): unsubscribe from asyncData watch when unmounting (#1185)
Browse files Browse the repository at this point in the history
Co-authored-by: drodichkin <[email protected]>
  • Loading branch information
daniluk4000 and drodichkin authored Apr 17, 2024
1 parent c1ea816 commit ac45690
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/bridge/src/runtime/composables/asyncData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,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)
}
}
Expand All @@ -308,7 +310,9 @@ export function useAsyncData<
return asyncData.refresh()
}
})
if (hasScope) {
if (instance) {
onUnmounted(off)
} else if (hasScope) {
onScopeDispose(off)
}
}
Expand Down

0 comments on commit ac45690

Please sign in to comment.