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

[v3.4rc19] Query ancellation appears broken in 3.4 #8496

Closed
sebastienbarre opened this issue Jul 14, 2021 · 8 comments
Closed

[v3.4rc19] Query ancellation appears broken in 3.4 #8496

sebastienbarre opened this issue Jul 14, 2021 · 8 comments

Comments

@sebastienbarre
Copy link

Intended outcome:

Previous GraphQL query is cancelled automatically when repeated.

Actual outcome:

Previous GraphQL query is cancelled... but new one is not triggered.

How to reproduce the issue:

I'll try to get a repo up and running, but I wanted to mention it quick, since it seems we are getting close to the official 3.4.

Essentially I have a classic, debounced "search" input field, where our user will type a few letters and the UI will perform a search query every X milliseconds once the field has debounced. This used to work nicely in 3.3; if a GraphQL query was still in flight by the time the UI next debounced, the new query would cancel the old one before the new one would take over.

See Network tab below, where 2 queries were cancelled, and the last one succeeded (since the user stopped typing):

image

This is no longer the case for me in 3.4rc19, the old one is cancelled... but the new one never goes through. See below, the old one is cancelled, but no new one in sight.

image

Versions

 System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 16.4.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.18.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 91.0.4472.114
    Safari: 14.0.3
@benjamn benjamn self-assigned this Jul 14, 2021
@benjamn benjamn added this to the MM-2021-07 milestone Jul 14, 2021
@hwillson hwillson added this to In progress in Release 3.4 Jul 15, 2021
@benjamn
Copy link
Member

benjamn commented Jul 16, 2021

@sebastienbarre Can you tell which beta/RC version introduced the regression? Was it @apollo/client@3.4.0-rc.19 specifically?

@sebastienbarre
Copy link
Author

@benjamn Indeed rc19. I'm trying to hunt down the reproduction repo that was used the last time cancellation was broken, see if it can show the same issue. Thx.

@sebastienbarre
Copy link
Author

That was #4955 back then, but now that I re-read it, it was cancelling not working when a component was unmounted, so it's a different case it seems.

@sebastienbarre
Copy link
Author

sebastienbarre commented Jul 18, 2021

@benjamn Do you guys have a reproduction repo that performs actual network requests, client<->server?
https://github.com/apollographql/react-apollo-error-template doesn't perform network requests, unless I missed something, so one can't see if they get cancelled...
Thx

@dylanwulf
Copy link
Contributor

dylanwulf commented Jul 18, 2021

@sebastienbarre You can return a cleanup function from an Observable, which would allow you to log request cancellations. See here for the Observable API

const link = new ApolloLink(operation => {
- return new Observable(async observer => {
+ return new Observable(observer => {
    const { query, operationName, variables } = operation;
-   await delay(300);
+   let completed = false;
+   delay(300).then(async () => {
      try {
        const result = await graphql(
          schema,
          print(query),
          null,
          null,
          variables,
          operationName,
        );
+       completed = true;
        observer.next(result);
        observer.complete();
      } catch (err) {
+       completed = true;
        observer.error(err);
      }
+   });

+   return () => {
+     console.log(completed ? 'request completed!' : 'request cancelled!', operationName, variables.searchTerm);
+   };
  });
});

@rossm6
Copy link

rossm6 commented Jul 19, 2021

I've just un-installed "3.4.0-rc.6" and installed "3.4.0-rc.18" to see if it helps with the problems I've been having but a useLazyQuery which has "fetchPolicy" of "network-only" and "nextFetchPolicy" of "cache-first" now gets cancelled and another IS NOT triggered.

My problem is #8514 (actually two problems).

@hwillson hwillson removed this from In progress in Release 3.4 Jul 20, 2021
@hwillson hwillson removed this from the MM-2021-07 milestone Jul 29, 2021
@hwillson hwillson added 2021-08 and removed 2021-07 labels Aug 3, 2021
@hwillson hwillson assigned brainkim and unassigned benjamn Aug 3, 2021
@brainkim
Copy link
Contributor

brainkim commented Aug 5, 2021

@sebastienbarre Can you check 3.4.5? That might have fixed this.

@sebastienbarre
Copy link
Author

@brainkim I tried with 3.4.4, it was still broken. I just tried with 3.4.5, and that indeed fixed it, thanks :)
Maybe I'll try to live dangerously and finally push 3.4 to production :) Thanks again.

chrismllr added a commit to chrismllr/ember-apollo-client that referenced this issue Dec 6, 2021
@apollo/client
Issues here surrounding cancelation which may be resolved with: apollographql/apollo-client#8496

@ember/test-waiters
Fixes an issue with embroider build: ember-graphql#404
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants