-
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
useQuery with fetchPolicy: 'standby' returns loading state as true when there is no loading happening #7564
Comments
tried to work around this issue by using |
Just in case anyone will bump into same issue and it's not resolved - here's the simplest (but dirtiest nevertheless) workaround that helped me
Still, would like this issue to be taken care of, just to keep code clean of what I did here, when possible |
You can probably use https://www.apollographql.com/docs/react/data/queries/#executing-queries-manually
|
I have a component that draws a chart with some statistical data. There are 4 filters for that data. I have a
useQuery
hook that looks like this:Variables for the query represent filters and are fed into component from parent component. I use 'standby' fetch policy due to the fact that we need to fetch data only when all filters are set and "Draw chart" button is pressed (which causes
refetch
to be called) and not on any change to any of the filters (due to performance reasons)Intended outcome:
I expected the
loading
field ofuseQuery
result to be true only during active refetch and to be false during initial render and consequent re-renders that shouldn't cause query fetching by themselvesActual outcome:
useQuery
returns result withloading
set to true on initial render that stays true untilrefetch
is called. Once refetch completes and component re-renders with new data,loading
is set to false. Once the component re-renders again with different query variables - then the faulty behaviour reintroduces itself - data fetching is skipped, butloading
is set to true once againHow to reproduce the issue:
https://codesandbox.io/s/loving-margulis-jy573
Here I've changed the following:
useQuery
to usestandby
fetch policyFetch persons
button to trigger refetchYou can see that initially component renders with
Loading...
instead of emptiness due to the issue. As soon as you click theFetch persons
button, everything will work as normal.Haven't implemented the case with updating variables, because this is a part of another issue that was acknowledged in this commentary.
Versions
System:
OS: macOS Mojave 10.14.6
Binaries:
Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
Yarn: 1.22.0 - /usr/local/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
Browsers:
Chrome: 87.0.4280.88
Firefox: 69.0.1
Safari: 14.0.1
tried on
@apollo/client
versions 3.2.5 and 3.3.6 (which appears to be in the latest tag at this moment)The text was updated successfully, but these errors were encountered: