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

QueryResult.fetchMore() triggers unexpected refetch of indirectly related "cache-and-network" queries #7939

Closed
Tracked by #9504
zenflow opened this issue Apr 1, 2021 · 6 comments

Comments

@zenflow
Copy link

zenflow commented Apr 1, 2021

Intended outcome:
When I call query.fetchMore() I expect this to never affect other queries or cause the other queries to be refetched.

Actual outcome:

When I call query.fetchMore() it sometimes causes a refetch of some "cache-and-network" query on the page.

It seems to happen when both queries (the one for which we call query.fetchMore() and the one that uses fetchPolicy: "cache-and-network") request data inside a common object type (e.g. __typename: "User").

How to reproduce the issue:

  1. Create or find an AC app where query.fetchMore() is used on a query that shares data with other queries shown on-screen
  2. Change the fetchPolicy for the other queries to "cache-and-network"
  3. Start the app, open it, open the network tab in Chrome devtools
  4. Trigger the query.fetchMore() in the app
  5. Observe that the other queries (which were set to "cache-and-network") are refetched after first (expected) request

Versions
@apollo/client v3.3.13

@Akryum
Copy link

Akryum commented Apr 7, 2021

Maybe related to #6916

@zenflow zenflow changed the title QueryResult.fetchMore() triggers unexpected refetch of all current "cache-and-network" queries QueryResult.fetchMore() triggers unexpected refetch of "cache-and-network" queries Apr 7, 2021
@zenflow
Copy link
Author

zenflow commented Apr 7, 2021

@Akryum Definitely somewhat related. I actually had noticed that issue too but with so many things going wrong I didn't document them all.

I'm able to work around that issue by adding nextFetchPolicy: "cache-first" wherever I'm using fetchPolicy: "cache-and-network", but sadly that doesn't help with this issue.

@zenflow zenflow changed the title QueryResult.fetchMore() triggers unexpected refetch of "cache-and-network" queries QueryResult.fetchMore() triggers unexpected refetch of unrelated "cache-and-network" queries Apr 7, 2021
@zenflow zenflow changed the title QueryResult.fetchMore() triggers unexpected refetch of unrelated "cache-and-network" queries QueryResult.fetchMore() triggers unexpected refetch of indirectly related "cache-and-network" queries Apr 7, 2021
@sebastienbarre
Copy link

I'm able to work around that issue by adding nextFetchPolicy: "cache-first" wherever I'm using fetchPolicy: "cache-and-network", but sadly that doesn't help with this issue.

I can observe that as well in 3.4.16, this is unfortunate.

@gastonmorixe
Copy link

gastonmorixe commented Dec 1, 2021

Spent 48 hours trying to understand why after executing fetchMore I had duplicate network requests. Sadly this happens with cache-and-network and network-only, be sure to set nextFetchPolicy: "cache-first"

Using v3.5.5

@benjamn benjamn self-assigned this Dec 1, 2021
@benjamn
Copy link
Member

benjamn commented Dec 1, 2021

This does sound like the same issue as #6916—see my thoughts in #6916 (comment).

The central idea is that complete cache results (broadcast after a successful fetchMore, for example) should be delivered immediately, by themselves, without triggering a network request for fetch policies like cache-and-network or network-only. Setting nextFetchPolicy: "cache-first" is a good workaround in the meantime because cache-first similarly avoids the network given a complete cache result.

I am actively working on that issue for v3.6. Unfortunately there are a number of test differences to work through, and those disruptions (even if they're ultimately improvements, like fewer network requests) needed more intensive beta testing than we thought we could get before v3.5 was released. I'm still hopeful it will be safe for a minor release (rather than AC4).

Closing this as a duplicate (please join the discussion in #6916), but happy to reopen if my planned changes don't (seem like they will) solve the whole problem here as well.

@gastonmorixe
Copy link

thank you @benjamn

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