-
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
QueryInfo needlessly retriggering queries in @apollo/client 3.x #6888
Comments
This reverts commit 24a4396, which prevented some legitimate updates in https://studio.apollographql.com. We will have to keep investigating #6888 to find a better solution.
@stephenh @evaneaston So, unfortunately, while #6891 made some problems go away, it also created other problems (regressions in https://studio.apollographql.com/). I've reverted that change in Since As always, some sort of reproduction would be ideal. |
@benjamn cool, thanks for the update. I tried to make a repro this morning and thought it was going to be really simple, i.e. just have multiple queries in a component where one of them has a mocked error, but famous last words I suppose, because I couldn't trigger it. :-/ :-) I don't have our production codebase in the same easy-to-repro spot anymore, but will watch for it, and keep my WIP repro around to see if I can come back to it. |
@benhjames @stephenh I can confirm that, after moving to I will see about making a minimal reproduction today. |
When using MockedProvider it works fine, not requerying unnecessarily. I can reproduce it running a simple create-react-app against a real graphql server and watching the network tab in the dev tools. I'll have to find an open/public graphql server that I reproduce this against. |
@benjamn You can find a reproduction of this issue there: https://github.com/upflowhq/react-apollo-error-template The bug happens when a component containing a query is unmounted before receiving the response. Then, any query using the same field but with different variables re-trigger the first query. |
I'm seeing this issue using MockedProvider as well. Trying to update from 3.0.2 -> 3.1.4 results in extra query requests hitting MockedProvider and triggering a "No more mocked responses for the query" error. From my investigation it looks like a call to |
This is still occurring on the latest (3.2.1) release |
Can confirm that this is still an issue in 3.2.5. For some reason, the dirty check in setDiff seems to be what is failing |
Just to reinforce that @ v3.2.5 I have the same problem |
@benjamn I noticed a lot of unnecessary calls refetching queries, and traced it down to this logic. I've applied your reverted PR, #6891 which solves the issue nicely. I suspect this is causing a decent amount of extra load for Apollo servers. What regressions did you see in https://studio.apollographql.com/ ? It looks like a fairly innocuous change. I'm trying to repro using https://github.com/upflowhq/react-apollo-error-template , but not quite there yet. Curious if anyone is seeing this in their apps like I did, or whether it's only been isolated to testing. |
I’m working on #7436, which appears to have the same cause. It is both humbling and motivating to see a bunch of competent devs each come to the same conclusion I did ( The nice thing is, if all of the team’s hypotheses are correct, this should be fixed in 3.4, which is currently in beta. Might be a good time to try it out! If everyone here can confirm that their bugs look like #7436, you might want to follow that one because I’ll be posting updates there. Otherwise, feel free to ping me and let me know and I’m happy to investigate. |
This should be resolved in |
Intended outcome:
I'm upgrading from apollo-client 2.x -> 3.x, and fixing a now-broken test that tests a React component that makes two
useQuery
calls:And I'm setting up
MockedProvider
with a valid response for the 2nd query and an error response for the 1st query:Note that I have to pass the
errorMyTasksResponse
twice (this varargs array towithApollo
ends up getting passed toMockedProvider
's mocks attribute).Actual outcome:
If I pass only a single
errorMyTasksResponse
(which is what we did on apollo-client 2.x), I get an "No more mocked responses" for theuseTasksQuery
on the 2nd time the query evaluates.However, none of the input variables are changing, so the query AFAICT should not be re-triggered a 2nd time.
Setting breakpoints, the 2nd query is triggered by
QueryInfo
snotifyTimeout
and ends up here, thinking that the query result has changed (see the expandeddiff
andoldDiff
results in the bottom variable pane):However, what's weird here is that
oldDiff.result
anddiff.result
are actually both{}
, i.e. it seems to me that this shouldn't be considered "not different". (Tangentially, I'm a little surprised in general thatdiff vs. oldDiff
is an===
instead of a structuralequal
, but I assume somewhere in the guts of the caching/etc. stuff, it's taking care of immutable/identity/something.)That said, it seems broken for this
{}
vs.{}
case. cc @benjamn apologies for the @ but you're all over the git blame here and I think would be best to at least guess if{} === {}
should actually be true for this boundary case.More guessing, but I wonder if
result = {}
because I'm setting up the mock with an error? I.e. I've hit this debug point with other queries and usuallyresult
isn't{}
.How to reproduce the issue:
I can work on the react-apollo-error-template thing but wanted to file this w/o at while it's in my head.
Note:
useCurrentInternalUserQuery
query, then the error response query works just fine and isn't needless re-triggeredjest.useFakeTimer
s and it's one of therunPendingTimers
that is triggering thenotifyTimeout
. I'm pretty sure that isn't causing the bug, but just in terms or reproducing.Versions
The text was updated successfully, but these errors were encountered: