Skip to content

Commit

Permalink
fix(useFetch): don't set isFetching to false when a request is aborte…
Browse files Browse the repository at this point in the history
…d because of a refetch (#3479)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
mweghorst and antfu committed Nov 9, 2023
1 parent 5f545be commit 75ca2bb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/useFetch/index.ts
Expand Up @@ -397,6 +397,8 @@ export function useFetch<T>(url: MaybeRefOrGetter<string>, ...args: any[]): UseF
if (timeout)
timer = useTimeoutFn(abort, timeout, { immediate: false })

let executeCounter = 0

const execute = async (throwOnFailed = false) => {
abort()

Expand All @@ -405,6 +407,9 @@ export function useFetch<T>(url: MaybeRefOrGetter<string>, ...args: any[]): UseF
statusCode.value = null
aborted.value = false

executeCounter += 1
const currentExecuteCounter = executeCounter

const defaultFetchOptions: RequestInit = {
method: config.method,
headers: {},
Expand Down Expand Up @@ -506,7 +511,8 @@ export function useFetch<T>(url: MaybeRefOrGetter<string>, ...args: any[]): UseF
return resolve(null)
})
.finally(() => {
loading(false)
if (currentExecuteCounter === executeCounter)
loading(false)
if (timer)
timer.stop()
finallyEvent.trigger(null)
Expand Down

0 comments on commit 75ca2bb

Please sign in to comment.