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

useQuery with network-only fetch policy renders data from cache when notifyOnNetworkStatusChange is true #12229

Open
levrik opened this issue Dec 16, 2024 · 5 comments

Comments

@levrik
Copy link
Contributor

levrik commented Dec 16, 2024

Issue Description

When using useQuery with fetch policy network-only and notifyOnNetworkStatusChange set to true, it behaves like network-and-cache, returning data from cache instead of ignoring the cache.

I'm using notifyOnNetworkStatusChange to get a re-render when recovering from an errored error by calling refetch so this is rather annoying that it breaks the network-only fetch policy for successful fetches.

Link to Reproduction

https://codesandbox.io/p/devbox/still-bash-52hmpn

Reproduction Steps

Without notifyOnNetworkStatusChange:

  1. Change filter to specific
    It flashes No Data
  2. Change filter back to all
    It flashes No Data

With notifyOnNetworkStatusChange:

  1. Change filter to specific
    It flashes No Data
  2. Change filter back to all
    No flash of No Data, instead renders data from cache

@apollo/client version

3.12.3

Copy link

triagster bot commented Dec 16, 2024

No dupes found!

@jerelmiller
Copy link
Member

Hey @levrik 👋

I would agree that I would expect that network-only shouldn't report a data value when variables change as that goes against what we describe for that fetch policy. From a quick bit of research (but no exhaustive testing), I believe the issue might have been introduced in 3.4.0 with 2d67ff1 which adds the condition that causes a cache value to be emitted when notifyOnNetworkStatusChange is true.

That was released 3 years ago so at this point it has the potential to be of a spicier change. We will likely target a fix for this in the next minor so we can call this out a bit more prominently.

In the mean time, I've opened #12230 which contains a failing test. Would you mind looking at the test I've written to make sure it adequately demonstrates the behavior you'd expect if this were fixed?

@levrik
Copy link
Contributor Author

levrik commented Dec 16, 2024

@jerelmiller Failing test case looks like I would expect it to behave. Please let me know if there's a fix available in a PR. I would add this as a local patch to the latest stable release in my project then so I don't have to wait on a formal release.

@jerelmiller
Copy link
Member

Unfortunately it looks like this might be a bit more complicated than meets the eye. I've got a patch in mind, but when trying it out, it breaks some refetch tests because it clears out the data value when the value is expected to remain until the network request has finished.

I'm going to take this issue to our team meeting on Wednesday to discuss what we'd like to do here and how refetch, polling, etc. is meant to behave with network-only.

@levrik
Copy link
Contributor Author

levrik commented Dec 17, 2024

@jerelmiller No problem. Take your time!

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

No branches or pull requests

3 participants