-
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 fails to return cached data when variables are changed #5659
Comments
what is your fetchPolicy? |
@RLech I didn't change it, so the default is used, which is |
We're having the same problem. As a temporary workaround we're using EDIT: We had to use |
I am just surprised no one from Apollo team has responded to this issue. It seems to be a big bug to me :( |
Not entirely sure, but I think this is by design. Every time you change a variables object in the useQuery, the query will be executed again. If you need to preserve the cached query data and run the same query with new variables you should use "fetchMore" function and manually update the cache with the result. |
@jsmircic I don't think this is by design. First, it works on previous versions. Second, If a query with a given variable has already been fired, data should be cached so that when this query is fired again, no network request should be needed, data should be returned from cache.
|
We are also experiencing this issue with 3.0.0-beta.16 Example that fail:
|
Here is a simple codesandbox reproducing the issue. Notes:
|
The problem doesn't exist with version Hopefully this is not intended behavior, as simply updating the variables in the |
The docs link to an example that relies on triggering a query execution by changing the query variables: So i also think this is a bug. It's a bit strange that this issue it not marked a |
Facing the same issue. Even manually calling EDIT: Is it really only introduced recently? I've spent hours looking into this now and it seems like a lot of people are facing this issue, but just phrasing it differently (" apollographql/react-apollo#2177 |
Updating to |
Verified that version |
After migrating to |
After migrating to3.0.0-beta.43 the issue still exists |
I've forked my previous codesandbox, updated to |
Hi guys. I have the same issued. But I think there is some magic under the hood. In my scenario useQuery() return an array inside the data object. IN my scenario my data is composed by 8 element. I can put some filters for backend. But, each field "user_id" inside those array elements has the same value. For some reason when backend return me with new data, apollo know that new result are the same as before (in this case an array of 8 elements), in fact an useEffect with data as dependencies in not called. And this is good. |
Consider the following queries
where
currPage
is a React local state variable. It will get updated when user paginatesIntended outcome:
When
currPage=1
, new data is fetched, whencurrPage=2
, new data is fetched... When user paginates to the previous page (page 1), because query withcurrPage=1
is already fetched, it should just read the cacheActual outcome:
When user paginates from page 1 to page 2, new data for page 2 is fetched, however, when user paginates back to page 1, cache is not read, data is still displayed for page 2
How to reproduce the issue:
Versions
The text was updated successfully, but these errors were encountered: