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
cache-and-network
fetch policy incorrectly reports cache hits as loading
#8669
Comments
@brainkim IIRC, you get |
While I believe this is true in practice, based on the number of similar issues I've come across in recent days, it seems like the current behavior doesn't match the spirit of the configuration. There's no clear path for surfacing this state to users that doesn't require refactoring the view logic when using the apollo-client/src/core/networkStatus.ts Line 28 in b214dd1
My current workaround for this is wrapping the
But I'd love to have a clear way to indicate there is an active "background fetch" or "refresh" or similar using Other discussions: |
This bug appears to make it impossible to test the loading behavior of The problem is that MockedProvider appears to prime the cache immediately, which fools any workarounds to detect edit: I'm no longer confident that I interpreted the test behavior correctly. When I inspected the data returned by my useQuery, it appeared to be unrelated data from a different query. |
We're also running into issues with cache-and-network incorrectly reporting the loading status (still). We want to refetch only if a network request is not already underway, but with cache hits reporting loading as true, we have no way to detect if a network request is happening when navigating back to a screen, for example. |
I'll +1 this still being an issue, makes using cache-and-network useless if you want to show a loading indicator. |
Bumping this issue again, this is a pretty massive UX hole that is difficult to support in its current state |
Hey there - seeing this for the first time since I'm new on the team 👋 I'll try to give my reasoning here - the other team members might disagree: This is nothing that we could quickly "fix" - adding a new That said, I'm unsure if it would be something to reconsider. Having this like it is right now to me looks equally expressive as having a new network status.
Now, adding another network status won't make this a lot "simpler"
No matter what we do, depending on how people structure their UI, some will be interested in And if I had to choose between those two options up there, the |
@phryneas Thank you for the thoughtful analysis and response. I would suggest that this is a documentation problem. We have learned new patterns for the behavior we want but first we had to discover that "loading" had unexpected behavior. It's such a tempting API but the simplicity doesn't teach developers how to go further or prepare them for other situations that will become painful as their application matures. It's a bit of a honeypot: attractive and easy to get stuck in. Imagine, then, if documentation (examples, guides, etc) demonstrated |
@cainlevy I agree, if that's something where we can improve the DX with documentation, we should definitely do that. |
@puglyfe I know comments aren't for just '+1's - but this workaround is absolute magic and emojis don't capture it:
I've had a thorn in my side for 18 months knowing that something was wrong with the query fetching. Every single page load that should be showing cached data was bringing up loading spinners. But it was a relatively small issue that no-one cared about. Finally seeing the component rendered properly from the cache almost brought a tear to my eye 😂 |
This is probably stupid - but I've created an npm package for this https://github.com/ianchanning/use-cache-network-query - maybe if enough people download it, it will persuade Apollo to change the defaults 😂 |
What about doing something as simple as changing the query status ordering comparison to check for e.g. Instead of this: if loading
return ...
if error
return ...
if data
return ... This 👇 if data
return ...
if loading
return ...
if error
return ... |
@pffigueiredo the problem I see there is that loading -> error -> data is a very common pattern and a very natural ordering for components, so it would be 'cache-and-network' forcing everyone to change. |
See 1834f5f
The text was updated successfully, but these errors were encountered: