-
-
Notifications
You must be signed in to change notification settings - Fork 521
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
Cached result is not instantly returned when fetchPolicy
is set to "cache-and-network"
#1315
Comments
We have identified the same issue. In the meantime, for this to be corrected, it would seem that if we add notifyOnNetworkStatusChange: true, at the useQuery level it works. But impossible to put it at the level of the config of apollo in defaultOptions. Wait and see :) |
some problem |
|
This old piece of code tried to get the result immediately by calling getCurrentResult(), except that the function will also set the internal "last" result if called without a `false` argument. This prevents `observer.next` from being called with the same initial value. The old code also conditionally ignored the result it just grabbed, and as a result the initial value ended up not being passed on to the application. The official Apollo React implementation does not have such special casing and simply grabs the result whenever `observer.next` is called. Align our code to that. Issue: vuejs#1315
If you're affected by this, could you please try #1388? You can setup linking manually or put |
@ishitatsuyuki fixes the issue for me. |
Heads up: there's now a release that ships the fix of @ishitatsuyuki https://github.com/vuejs/apollo/releases/tag/v4.0.0-beta.1 |
This is fixed in vue-apollo 4.x, but the same logic exists in vue-apollo 3.x, see: apollo/packages/vue-apollo/src/smart-query.js Lines 115 to 123 in fdc6fb8
Removing the code also fixes the issue, but I found that at least in 3.x, the code does something. Consider the following:
with the above code, the child component has the cached data before the component tries to render the template. Without the code, it doesn't (and you have to use v-if etc. to wait for the data) This brings me to the point that vue-apollo is still not well tested.
As long as the testing strategy is subpar, errors like this will pop up again and again. |
I ended up patching the @vue/apollo-option directly inside vue-apollo-option.esm.js for now, I'm not 100% sure of the logic, but it solved the issue for us with "cache-and-network" not returning any cached results. Also network-only and cache-only seemed to work as expected.
|
Describe the bug
When settings the query options with
{ fetchPolicy: "cache-and-network" }
, the cached result is not instantly returned.Instead, it waits until the data is fetched from the server to return the result.
To Reproduce
Steps to reproduce the behavior:
useQuery
with the following options{ fetchPolicy: "cache-and-network" }
variables1
andvariables2
variables1
, thenvariables2
, thenvariables1
again — e.g.const { result } = useQuery(query, variable1, { fetchPolicy: "cache-and-network" })
variables1
, the change inresult
won't be instantaneous. Instead, it will wait for a few seconds before updating.Expected behavior
The cached result should be returned instantly.
Versions
vue: "^3.2.16"
@vue/apollo-composable: "^4.0.0-alpha.16"
@apollo/client: "^3.5.8"
The text was updated successfully, but these errors were encountered: