v3.0: loading: true for first render always, even if all data is available in cache
See original GitHub issueIntended 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 with loading: 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:9 (4 by maintainers)
Top GitHub Comments
@nsmith7989 This issue should be fixed in
@apollo/client@3.1.0-pre.3
, thanks to #6710, if you want to give it a try. Here’s an updated version of your reproduction that seems to show the desiredloading: false
behavior: https://codesandbox.io/s/dazzling-snow-6vvx3@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
loading: false
it renders children, which happens to run the exact same query as the parent.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
loading: false
and data. In 3.0 the first render isloading: true
and data from the cache, then a second render whereloading: false