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

Timeout timer invalidate in useFetch. #27202

Closed
KyleXie opened this issue May 14, 2024 · 0 comments · Fixed by #27308
Closed

Timeout timer invalidate in useFetch. #27202

KyleXie opened this issue May 14, 2024 · 0 comments · Fixed by #27308

Comments

@KyleXie
Copy link

KyleXie commented May 14, 2024

I'm not sure if it's a bug here. I see the timeout timer is not being cleared after the request, so it'll trigger even if the request gets a response in time. It could happen that the timeout timer of a previous request may trigger while the next request is ongoing if we call the refresh function of useFetch, so it may accidentally cancel the next request.

let controller: AbortController
const asyncData = useAsyncData<_ResT, ErrorT, DataT, PickKeys, DefaultT>(key, () => {
controller?.abort?.()
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
/**
* Workaround for `timeout` not working due to custom abort controller
* TODO: remove this when upstream issue is resolved
* @see https://github.com/unjs/ofetch/issues/326
* @see https://github.com/unjs/ofetch/blob/bb2d72baa5d3f332a2185c20fc04e35d2c3e258d/src/fetch.ts#L152
*/
const timeoutLength = toValue(opts.timeout)
if (timeoutLength) {
setTimeout(() => controller.abort(), timeoutLength)
}

@nuxtbot nuxtbot changed the title Timeout timer invalidate in useFetch Timeout timer invalidate in useFetch. May 14, 2024
@danielroe danielroe self-assigned this May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants