-
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
Variables not updated when refetch with useQuery() + skip: true #8952
Comments
@chenesan Sorry for the delayed response! So looking at your repro on Code Sandbox, I’m wondering why the hook which calls |
@brainkim
Just rewrite the effect with
Yes, this can resolve the problem. But, before migrate to v3 we don't need to pass new variable and apollo-client can take the newest variables from options to refetch even though the query is skipped. After #6752 if we don't pass new variables it will ignore the variables passed to skipped query instead, which is a breaking change I think? For this behavior change, we have to check if we call refetch without new variables all over our codebase 😢
Tried |
@chenesan Hello! it's been a while but I'm curious if this is still an issue for you and if you can try out 3.6.7. We've recently done a lot of improvements to |
I can try this next week. |
Tried 3.6.9 and looks good now! thanks @jpvajda |
@chenesan Awesome! We appreciate the confirmation. |
Recently our teams just migrated apollo-client from v2 to v3, and found out a behavior change:
In our codebase we call
useQuery()
withskip: true
, updating the variables during rerender, and call the returnedrefetch()
to fire the query, for example:We do
useQuery() + skip: true + refetch
becauseuseLazyQuery()
returns void instead of promise. We have used this workaround for a long time.Then we found out that, in v3 (3.4.10), when
refetch()
, the request will not bring the latest variables but the initial variables. In above case, thecount
in variables will always be0
.In v2, the variables will always be updated, which is the behavior we expected.
Related PR
The behavior change seems start from #6752. It prevents network request when options update with
skip: true
, but it also prevents options update.This comment shows that a portion of apollo-client users do use
useQuery() + skip: true + refetch()
as a substitution ofuseLazyQuery()
. For us, this behaivor change is an implicit breaking change and cause unexpected bug during the migration from v2 -> v3(we spend one month discovering this issue after finishing v3 migration). I hope we can fix this behavior change so it would be less painful for people migrating to v3.Intended outcome:
When call
refetch()
withuseQuery() + skip: true
, the query options should be updated.Actual outcome:
When call
refetch()
withuseQuery() + skip: true
, the query options are not updated.How to reproduce the issue:
codesandbox: https://codesandbox.io/s/recursing-goodall-mcd76
The request will fired when renderTimes > 3, Notice that the fired request will always bring outdated variables
limit: 1
instead of updatinglimit
withrenderTimes
.Versions
The text was updated successfully, but these errors were encountered: