Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
refactor: simplify fetch abort
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Sep 27, 2022
1 parent 45af8dc commit 8a42507
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions packages/nuxt/src/app/composables/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,12 @@ export function useFetch<
let controller: AbortController

const asyncData = useAsyncData<_ResT, ErrorT, Transform, PickKeys>(key, () => {
controller?.abort?.()
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
return $fetch(_request.value, { signal: controller.signal, ..._fetchOptions }) as Promise<_ResT>
}, _asyncDataOptions)

const originalRefresh = asyncData.refresh

asyncData.refresh = asyncData.execute = (opts?: AsyncDataExecuteOptions) => {
if (opts?.override) {
controller?.abort?.()
}
return originalRefresh(opts)
}

return asyncData.then(r => ({ ...r, refresh: asyncData.refresh, execute: asyncData.refresh }))
return asyncData
}

export function useLazyFetch<
Expand Down

0 comments on commit 8a42507

Please sign in to comment.