'loading' flips to true at first even with fetchPolicy 'cache-only'

Migrating from @apollo/client v2 to v3, we encountered a test failure where the test is making a ‘cache-only’ request, and expects to never see ‘loading’ true. On v2 this test passed, but in the latest v3 it fails. useQuery still doesn’t try to make a network request, but it does initially flip over to ‘loading’. Is this expected behavior? It does make sense that while accessing the cache we’d see ‘loading’, but I’m unclear on what the intention is and whether it changed at some point.

The first test below is the one with ‘cache-only’ ‘loading’ true, the second one uses ‘skip’ and never sees loading true, and the third is cache-only BUT populates the cache with the expected query first and does not ever see ‘loading’ true. Are the 1st and 3rd tests inconsistent?

https://codesandbox.io/p/devbox/runtime-feather-47dkjr?file=%2Fsrc%2Ffoo.test.js%3A106%2C48&workspaceId=d52fd799-1c03-4c2e-846c-ebc95cde47b0

Also found this topic where they seem to be seeing the opposite behavior: "loading" property when Apollo is fetching from cache

That is indeed weird - I’ve opened reproduction around `useQuery` loading with `cache-only` on an empty cache by phryneas · Pull Request #12021 · apollographql/apollo-client · GitHub to look into this further and discuss it with my colleagues.

Thank you for the report and reproduction - please feel free to chime into the discussion over in the repro PR :slight_smile:

1 Like