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

feat(useFetch): cancel previous request #2750

Merged
merged 2 commits into from Feb 11, 2023
Merged

feat(useFetch): cancel previous request #2750

merged 2 commits into from Feb 11, 2023

Conversation

Alfred-Skyblue
Copy link
Member

Description

closes #2677

When executing requests continuously or monitoring url ref changes, the previous request will be automatically terminated to ensure that the obtained data is the most current requested data.

Additional context

useFetch


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@Alfred-Skyblue Alfred-Skyblue changed the title fix(useFetch): cancel previous request feat(useFetch): cancel previous request Feb 10, 2023
@wheatjs
Copy link
Member

wheatjs commented Feb 11, 2023

Makes sense, although I wonder if we should make this an option. I could think of a scenario where perhaps you are logging data to a server and making multiple rapid requests to the endpoint. In that instance I don't think we would want to cancel the requests.

@Alfred-Skyblue
Copy link
Member Author

@wheatjs I think the cancellation request is unilateral, the server does not stop execution just because the front end cancels the request, it cancels the request just to ensure that the data obtained is up to date

@wheatjs
Copy link
Member

wheatjs commented Feb 11, 2023

Ah you are right, I was thinking maybe on slow networks before the request was sent, but wasn't able to actually reproduce that scenario

@wheatjs wheatjs merged commit cd9d6b4 into vueuse:main Feb 11, 2023
@Alfred-Skyblue Alfred-Skyblue deleted the fix-useFetch branch February 15, 2023 00:49
@s-prechtl
Copy link

I'm using refetch: true and the reqeusts are cancelled, but I get the error state: AbortError: The user aborted a request., even though the last request sent ends in status code 200 and sends data. Am I missing something, or is this a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useFetch - options for gracefully refetching
3 participants