-
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
Query Functionality with onCompleted
is broken in v3.0.0 release (CodeSandbox repro)
#6636
Comments
@benjamn Take a look here and observe the console https://codesandbox.io/s/apollo-reference-equality-1exes?file=/src/App.js While Also observe how the |
I noticed that even if I change the Related to apollographql/react-apollo#3729 In general, this seems like a bug that may be unrelated to lazy querying, but I feel it's something on the "core" functionality of querying since it manifests in many different ways |
I'm using |
I've noticed that this is also happening with a regular |
Yeah I also mentioned that I feel that this is not necessarily tied only to lazy queries. Will update description |
onCompletted
is broken in v3.0.0 release (CodeSandbox repro)
onCompletted
is broken in v3.0.0 release (CodeSandbox repro)onCompleted
is broken in v3.0.0 release (CodeSandbox repro)
Same problem. Endless request loop when using onCompleted in one of my applications after upgrading. Might go back to apollo-boost for now. |
This issue was fixed in #6588, and will be coming in |
Heads up: we're not quite ready to publish Update: thanks to @3nvi's reproduction, I can confirm the fix: https://codesandbox.io/s/apollo-reference-equality-t0ttx |
Perfect. Thanks a lot @benjamn ! |
@benjamn I just tried the latest version I tried replicating it in your sandbox but I can only replicate it with
|
Thank you so much @benjamn ! It's working for me, great! |
@benjamn I just tried @apollo/[email protected] and it's still a no go. This issue might be slightly different than the 2 year old one (auto archived without fix and reopened by me apollographql/react-apollo#3968 then repo archived). But the gist for me is that |
@apollo/[email protected] worked for me. I had to delete the |
Hi there. The cache is enabled, but I don't use I'm using But now working normally (after update version). |
Still getting stuck with infinite loop of requests to api. it's happening only when i call setAuth to save state with context api. |
@zeeshanaligold try adding a flag to check for the user in the
|
@zeeshanaligold try with import { useCallback } from 'react'
...
const handleOnCompleted = useCallback(({ user }) => {
setAuth({ user, isAuthenticated: true })
}, [])
const { loading, error } = useQuery(GET_USER, {
onCompleted: handleOnCompleted
}) |
@orrybaram it's fix the infinite loop issue but still sending 2 requests. One more issue when logout trigger & authedUser will set to false then again new request will go to graphql |
@Tautorn i did try it but still same issue. |
@zeeshanaligold Could you reproduction this issue in some tool like codesandbox? If possible I hope. |
Does 3.1.1 include this fix? |
Not fixed on 3.1.1. It still only works by wrapping |
3.1.1 is working for me |
@benjamn Given the fact that 3.3.0 launched without it, is there a chance we can get an update on the state of things? Is it something that's within your priorities or should we try and work around this for the time being. As always, I appreciate you' re juggling a lot of things, so thanks in advance |
👍 on this, thanks for the work you're putting into this project! |
Any update on this? I'm getting this error on version
I found an orthodox solution, implemented useEffect which acts as a completed validator:
Then my useEffect:
|
Would be nice to have a proper onComplete fired on refetch even if it's from cache. The most similar behavior I could come up with meanwhile was:
|
adding that
|
This comment has been minimized.
This comment has been minimized.
This should be fixed in 3.5, please try it. |
@brainkim it's not. Unfortunately, I believe it's now worse than before, since Please refer to this comment #6636 (comment) and its reproduction instructions to validate the bugs. I was able to validate them in [email protected]. Should we re-open this? |
No, I would disagree with that. As far as I can tell, the original issue was about React render-looping when there was some combination of fetch policy and
I’ll sift through this monster thread again to see if I can codify the general expectations as unit tests. Thanks for the patience. |
This issue was not fixed for three years... |
@brainkim I'm new to using Apollo Client. My "blank slate" expectation of reading the |
We believe this is now fixed; if anyone is still encountering this issue in |
@hwillson indeed now the One of the things that still lingers is the fact that changing variables on a lazy query (that has previously been executed), fires it automatically. Due to the nature of lazy querying, I'd expect that changing variables wouldn't automatically run a lazy query, but this may be by design. I personally consider it a bug (and part of this ticket), but let me know your thoughts. |
Some core lazy querying functionality through
useLazyQuery
seems a bit off.Specifically, when a lazy query (through a
useLazyQuery
hook) returns an error, then Apollo seems to start endlessly querying the server. The same thing happens if you give it afetchPolicy
ofnetwork-only
(or anything that doesn't search the cache first).Related: apollographql/react-apollo#4044
At the same time, if the lazy query function (returned by
useLazyQuery
) gets called more than 1 times, then no callbacks are fired. TheonCompleted
doesn't fire again. TheonCompleted
fires on the 1st successful run of the "query" function and then consecutive invocations of the lazy query function, don't triggeronCompleted
callback (they should, since you can't have conditional business logic based on whether the data is cached or not!)Related: apollographql/react-apollo#4000
Funnily enough, using
client.query()
works fine. All this used to work perfectly during the beta (I think I've verified that something occurred after@apollo/[email protected]
), but now it doesn't.UPDATE: I've added a codesandbox that reproduces it
Intended outcome:
network-only
fetch policy shouldn't trigger endless API querying on a lazy queryonCompleted
should fire every time a lazy query gets successfully executedActual outcome:
network-only
fetch policy start an endless loop of requestsonCompeted
gets fired at most once regardless of the number of invocationsHow to reproduce the issue:
fetchPolicy
tonetwork-only
or force an API error on a lazy queryonCompleted
callback.Versions
System:
OS: macOS 10.15.2
Binaries:
Node: 12.18.0 - /usr/local/bin/node
Yarn: 1.19.0 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Browsers:
Chrome: 83.0.4103.116
Firefox: 72.0.2
Safari: 13.0.4
npmPackages:
@apollo/client: ^3.0.2 => 3.0.2
apollo-link-error: ^1.1.12 => 1.1.13
The text was updated successfully, but these errors were encountered: