Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useFetch): don't set isFetching to false when a request is aborted because of a refetch #3479

Merged
merged 4 commits into from Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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