-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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.0: loading: true for first render always, even if all data is available in cache #6659
Comments
This is likely the same underlying issue as #6651, but this is reproducible without a SSR setup. |
Same issue without SSR |
@nsmith7989 Thanks for the reproduction (it really helps), but I'm not seeing how the data is already available in the cache. I agree we should be able to return a complete |
@benjamn not completely sure I'm following. In the reproduction above the cache is primed because a parent component ran a query and returned a loading indicator while it was in flight. After parent gets back My assumption is that the parent component primed the cache and the child is essentially reading from the cache. In 2.0 the scenario we get is |
@nsmith7989 Ack, sorry, I see how that works now. No need to update the repro. We'll take a look and get back to you soon. |
PR #6353 explains the rationale for switching to a cache-first FetchPolicy after an initial cache-and-network or network-only policy. When #6365 was implemented, options.fetchPolicy was examined only once, at the beginning of fetchQueryObservable, so the timing of changing options.fetchPolicy did not matter as much. However, fixing #6659 involves checking the current options.fetchPolicy whenever the QueryData class calls this.currentObservable.getCurrentResult(), so it's now more important to delay changing options.fetchPolicy until after the first network request has completed.
@nsmith7989 This issue should be fixed in |
Thanks @benjamn. I can confirm that this looks good in the reproduction. I will try it on my own app |
We've tested on our own large React codebase and |
Following up: we just published |
Intended outcome:
Attempting to upgrade to @apollo/client@3.0 but I found that my application was rendering a lot more often than it was in 2.0. We have several components that are hooked into the same query, they usually only render once if the query has already completed earlier.
Actual outcome:
In 3.0 it appears that every query will have
loading: true
even if the cache data can satisfy the query. It will then immediately re-render withloading: false
How to reproduce the issue:
I recreated the 3.0 issue here: https://codesandbox.io/s/serene-yalow-lvfm9 look at the console and you'll observe the behavior.
Compared to 2.0: https://codesandbox.io/s/determined-galois-e1w2w if you look at the console the same query only renders 1 time with
loading: false
Versions
@apollo/client@3.0.2
The text was updated successfully, but these errors were encountered: