-
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
reproduction around useQuery
loading with cache-only
on an empty cache
#12021
base: main
Are you sure you want to change the base?
Conversation
|
size-limit report 📦
|
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Bisecting with import gql from "graphql-tag";
import { ApolloClient, InMemoryCache } from "../../../core";
import { useQuery, ApolloProvider } from "../../../react";
import { renderHook } from "@testing-library/react";
import * as React from "react";
it("flips to `loading: true`, then `loading: false` on an empty cache when using `cache-only`", async () => {
const query = gql`
query {
hello
}
`;
const client = new ApolloClient({ cache: new InMemoryCache() });
const renders = [];
renderHook(
() => renders.push(useQuery(query, { fetchPolicy: "cache-only" })),
{
wrapper: ({ children }) => (
<ApolloProvider client={client}>{children}</ApolloProvider>
),
}
);
await new Promise((resolve) => setTimeout(resolve, 1000));
expect(renders[0].loading).toBe(true);
expect(renders[0].data).toBe(undefined);
expect(renders[1].loading).toBe(false);
expect(renders[1].data).toBe(undefined);
}); |
Okay, this has been the behaviour since 3.0.0: https://codesandbox.io/p/sandbox/ac-12021-nk7265 |
Thanks for digging into this! If you do decide that |
Hey @jpm4, a short update for this: This is something we'd like to change, but it has been around for the whole 3.x series, so we will postpone it until 4.x. |
This came up in
https://community.apollographql.com/t/loading-flips-to-true-at-first-even-with-fetchpolicy-cache-only/7771
I could at least reproduce this in 3.10 and 3.11, so it's not a result of the
useQuery
rewrite.The question is also what the correct behaviour would be here.
v2 apparently had
loading: false
, butdata: undefined
.I would argue that a constant
loading: true
would be preferrable until something else fills in the cache. 🤔I'll rewrite the test in an older style and do some more bisecting.