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

Cancel fetchMore network requests #107

Open
dylanwulf opened this issue Jun 4, 2019 · 6 comments
Open

Cancel fetchMore network requests #107

dylanwulf opened this issue Jun 4, 2019 · 6 comments

Comments

@dylanwulf
Copy link

dylanwulf commented Jun 4, 2019

Hello,
I would like to be able to cancel fetchMore requests in these two scenarios:

  1. When the Query component unmounts
    Currently it seems like the initial query request will get cancelled when the component unmounts, but there is no way to cancel a request which was initiated with the fetchMore function. I think this would solve apollo-client issue #4114.
  2. When the variables change
    If the variables are changed while a fetchMore request is still in progress, the results from that fetchMore request are going to be completely useless; might as well just cancel the request. I think this would solve apollo-client issue #2813

Thank you!

Edit: This could possibly be considered a migration from apollo-client #3360

@hogiyogi597
Copy link

+1

@i8ramin
Copy link

i8ramin commented Oct 25, 2019

Hi any updates or workaround for this?

@dylanwulf
Copy link
Author

@i8ramin I don't have any way to cancel the network request, but I did find a way to work around issue apollographql/apollo-client#2813
I just hold onto the query variables in a ref, then in the updateQuery function i do a deep comparison between the fetchMore variables and the current query variables

@sgtpepper43
Copy link

sgtpepper43 commented Jun 17, 2020

For the "when the Query component unmounts" scenario, it would be great if we could at least not get an error thrown when this happens. I don't necessarily care if the request gets cancelled (which doesn't look to be possible with fetch), I just don't want an error in my logs for an issue that doesn't actually impact the user.

Edit: Wait, I found this apollographql/apollo-client#4114 (comment). Still there should probably be a better way of handling it. Or at least this should be documented maybe, I dunno.

@hwillson
Copy link
Member

👋 @dylanwulf - just touching base on this; do you think this is still a significant issue with current day @apollo/client? We're happy to dig into this if so.

@dylanwulf
Copy link
Author

@hwillson Thank you for checking in! I don't think this is as big of a problem with modern-day apollo client, but it's still something which I feel would make sense to implement eventually. Currently, if a query is mounted and then unmounted the network request will be canceled. But if a query is unmounted after changing the variables or calling fetchMore, the request will not be canceled. To me this feels inconsistent and confusing, but doesn't really cause any problems so it's not super important that it get solved. Neither of the issues I referenced in the original description (apollographql/apollo-client#4114 and apollographql/apollo-client#2813) are a problem for me anymore.
(I'm currently on @apollo/client@3.3.21 so please excuse me if anything I stated above is no longer true in the latest version)

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

No branches or pull requests

5 participants