question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v3.0: loading: true for first render always, even if all data is available in cache

See original GitHub issue

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 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:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
benjamncommented, Jul 27, 2020

@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 desired loading: false behavior: https://codesandbox.io/s/dazzling-snow-6vvx3

4reactions
nsmith7989commented, Jul 22, 2020

@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 is loading: true and data from the cache, then a second render where loading: false

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
If all data is available locally, useQuery returns that data and doesn't query your GraphQL server. This cache-first policy is Apollo Client's default...
Read more >
Suspense for Data Fetching (Experimental) - React
So fetching all data for the new screen and then rendering is often a more practical option. Approach 3: Render-as-You-Fetch (using Suspense). In...
Read more >
How to derive "loading" from useSWR between fetches ...
Let's say I change the id via the UI and want to show loading indicator. Because data is no longer undefined , the...
Read more >
Optimize Largest Contentful Paint - web.dev
If the LCP element does not require a resource load to render (for example, ... to each other, so it's best to always...
Read more >
useQuery | TanStack Query Docs
const { data, ... If true , failed queries will retry infinitely. ... loading if there's no cached data and no query attempt...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found