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

Detecting cache-and-network refetch via networkStatus #4693

Closed
codepunkt opened this issue Apr 11, 2019 · 3 comments
Closed

Detecting cache-and-network refetch via networkStatus #4693

codepunkt opened this issue Apr 11, 2019 · 3 comments

Comments

@codepunkt
Copy link

When fetching a query using fetchPolicy cache-and-network, refetching it after the first fetch sets loading as if it was the initial fetch, so i'm trying to use networkStatus to detect a difference between initial fetch and background refetch.

Intended outcome:

networkState is set to different values while request is inflight for initial and background cache updating requests.

Actual outcome:

networkState is 1 while fetching and 7 or 8 when finished - regardless of initial fetch or later background refetch.

How to reproduce the issue:

Simple example at https://codesandbox.io/s/24nkjm76q0

If networkStatus is not used for this, how do i detect the difference?

@timhwang21
Copy link
Contributor

This has been an annoyance for me as well, I've gotten around it by checking to see if data is not empty as well.

@pl12133
Copy link

pl12133 commented Apr 15, 2019

Looks like #3660

@benjamn benjamn self-assigned this Apr 30, 2019
@benjamn benjamn added this to the Release 2.6.0 milestone Apr 30, 2019
benjamn added a commit that referenced this issue Apr 30, 2019
Blindly setting networkStatus to NetworkStatus.loading after the client
part of a cache-and-network query was destroying useful information about
the status of the request. Instead, we should use NetworkStatus.ready only
when the request is complete, and leave networkStatus untouched otherwise.

Should fix #1217.
Should fix #3660.
Should fix #4693.
benjamn added a commit that referenced this issue Apr 30, 2019
Blindly setting networkStatus to NetworkStatus.loading after the client
part of a cache-and-network query was destroying useful information about
the status of the request. Instead, we should use NetworkStatus.ready only
when the request is complete, and leave networkStatus untouched otherwise.

Fixes #3660, #4693, and apollographql/react-apollo#1217.
benjamn added a commit that referenced this issue Apr 30, 2019
Blindly setting networkStatus to NetworkStatus.loading after the client
part of a cache-and-network query was destroying useful information about
the status of the request. Instead, we should use NetworkStatus.ready only
when the request is complete, and leave networkStatus untouched otherwise.

Fixes #3660, #4693, and apollographql/react-apollo#1217.
@benjamn
Copy link
Member

benjamn commented May 21, 2019

Closing since we just published the final version of apollo-client@2.6.0 to npm, including the fix for this issue! See CHANGELOG.md if you're curious about the other changes in this release.

@benjamn benjamn closed this as completed May 21, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 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

4 participants