-
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
fix(regression): avoid calling useQuery
onCompleted
for cache writes
#10229
fix(regression): avoid calling useQuery
onCompleted
for cache writes
#10229
Conversation
d903cf4
to
e763b92
Compare
Thanks @benjamn! I've added that condition in e763b92. Curiously, while the tests are still passing locally they are now consistently failing on CI... wondering if our CI runners are under heavy load or there's some other reason tests would suddenly start failing (it's even a test added by this PR that is consistently failing now, but was consistently passing before). |
Welp... tests are green now. Ready for a final pass 🙇♀️ |
useQuery
onCompleted
for cache writes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alessbell!
@alessbell: Given that this PR has been merged into v3.8 - is it correct that the intended behaviour of (following up on #5531 (comment)) |
There are a few related issues pointing to a regression that occurred between
v3.4.17
andv3.5.0
and greater: writes to the cache (it doesn't matter how the cache update occurs: directly viacache.writeQuery
, via a separateuseMutation
call, etc.) trigger theonCompleted
callback passed touseQuery
, whereas inv3.4.x
,onCompleted
was triggered when the initial network request completed, and not on subsequent cache writes.cache-and-network
: No way to determine if the network request has completed #10059onCompleted
callback ofuseQuery
executes from cache writes. #10076My proposed solution here is to compare the previous and current
result
's loading states: if the loading state doesn't change,onCompleted
won't re-fire. This approach has the benefit of working as expected with thenotifyOnNetworkStatusChange
option which will causeonCompleted
to fire after subsequent network requests ifnotifyOnNetworkStatusChange
is set totrue
.refetch
andpollInterval
Calls to
refetch
and queries withpollInterval
configured work the same way: they don't update theloading
state unlessnotifyOnNetworkStatusChange
istrue
. If we'd like to preserve the current behavior whereby polling queries fireonChange
when watched cache data changes without updatingloading
/networkStatus
, we can keep the condition in b521d12#diff-fb7fa652de6d84c08b87344a06a4d120b664c6e8bf491d16575794c755141477R517. I'm in favor of keepingonCompleted
execution consistent across the board, but would love input on this.There also seems to be some confusion re: polling and
onCompleted
: looking at this issue, the callback is not repeatedly firing because the cache never changes. #5531Checklist: