-
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 loading state stays true after fetch finishes #6334
Comments
This issue is a blocker for my team upgrading -- we're currently stuck on beta-44. I reproduced this on beta-54 just now; however changing the This issue is especially notable on our app's "dashboard" view which features about a dozen queries firing simultaneously. On the upgraded version branch, some of the queries work fine but several of them just spin forever because |
This seems to be a recurring issue. The following issues seem to be related:
I know these are all links from the deprecated repo, but my point is that this issue is CONSTANTLY happening. What gives? How is this such a problem? Let me explain our scenario so you can see why this issue is so bonkers. We make three requests for paginated data. One for the previous page, current page, and next page. When you deep link into the application and it does it's initial render/load everything works out fine and the pages load. Example of requests:
If you add another query parameter, of course, the hooks fire off new network requests. Like so:
Note that the first request returned the same data both times: Riddle me this: why is the cache not using a different key when we change the query parameters? Why does the result of one request with one set of query params affect the loading state of a request with another set of query params? How is that even a thing?!?! Sorry for the 🧂. This bug has been a real PITA lately. I'm using this venting as therapy. Don't take this personally. I love you all. |
Note on the above: I'm more than happy to help out with updating the cache key logic, but a quick tip on where to start looking would be appreciated. |
We're encountering this issue on RC If it helps, this state appears to trigger when results are identical to that of previous queries as @julian-sf mentioned. Unfortunately having to use const { data, loading } = useQuery(GET_DELIVERIES, {
fetchPolicy: 'no-cache',
variables: {
params: {
...baseParams,
...sortParams,
searchQuery: query,
limit: pageSize,
offset: (page - 1) * pageSize,
},
},
}) |
Updates for me:
This corroborates what others in this thread have said. I actually reproduced the issue closest to my use case in this sandbox: https://codesandbox.io/s/autumn-darkness-8b69l (check the console for more info in there) |
I think there's a related but possibly separate issue in export interface QueryType {
result: string[];
}
const { data, loading } = useQuery<QueryType>(THE_QUERY);
console.log(data, loading); we get the following console messages:
The query is never refetched or anything, and there's no changing query variables. Changing the fetch policy to |
Same issue here. Using Next.js app. When initially spinning up app > loading TRUE > loading FALSE > DATA. Then when navigating to another page and back again > Loading TRUE, Loading TRUE, Loading TRUE, etc. Even when its a cached query with data ready to go. Got around it this way:
But, still.... |
Have the same problem in
After first load In |
I experience exactly the same behavior with
see that commit: c76804e |
Some update: in my case
and my query in cache empty and looks like:
If my array is not empty - all work fine. |
Thanks for the great reproduction and details here. This issue is being caused by the way we snapshot and track differences between results, to help prevent unnecessary computations. For example, removing the apollo-client/src/core/ObservableQuery.ts Line 594 in 2d61e5c
We'll tweak the snapshot approach a bit, and have a fix for this out shortly. |
Any solution?? |
I have a similar issue. I'm using |
@edmundas-ramanauskas This version does not work for me.
I can confirm this version works as recommended in OP. |
Issue #6334 exposed a problem where the `lastResult` mechanism we use to prevent duplicate subscription notifications (when data hasn't changed) can unintentionally block certain results from propagating through Apollo Client. This leads to issues like loading states not being updated properly, due to new partial results looking similar to last results. This commit ensures that last results are properly cleared out when new partial results come in. Fixes #6334.
Issue #6334 exposed a problem where the `lastResult` mechanism we use to prevent duplicate subscription notifications (when data hasn't changed) can unintentionally block certain results from propagating through Apollo Client. This leads to issues like loading states not being updated properly, due to new partial results looking similar to last results. This commit ensures that last results are properly cleared out when new partial results come in. Fixes #6334.
Issue #6334 exposed a problem where the `lastResult` mechanism we use to prevent duplicate subscription notifications (when data hasn't changed) can unintentionally block certain results from propagating through Apollo Client. This leads to issues like loading states not being updated properly, due to new partial results looking similar to last results. This commit ensures that last results are properly cleared out when new partial results come in. Fixes #6334.
Issue #6334 exposed a problem where the `lastResult` mechanism we use to prevent duplicate subscription notifications (when data hasn't changed) can unintentionally block certain results from propagating through Apollo Client. This leads to issues like loading states not being updated properly, due to new partial results looking similar to last results. This commit ensures that last results are properly cleared out when new partial results come in. Fixes #6334.
Hi all - |
Thanks for the update. I have upgraded but I'm still getting the same issues with useLazyQuery. Thanks |
@riccoski would you mind providing a small runnable reproduction that shows the problem? |
I have created one here: https://codesandbox.io/s/quiet-sea-hj7es?file=/src/App.js When you click 'Get data' the loading state persists and the onCompleted doesn't fire. Thanks |
Thanks @riccoski - this appears to be a different issue. If you comment out the |
Will do! Thanks
On Thu, 11 Jun 2020 at 11:55, Hugh Willson ***@***.***> wrote:
Thanks @riccoski <https://github.com/riccoski> - this appears to be a
different issue. If you comment out the fetchPolicy line it works
properly, which is different than the original issue here. Would you mind
opening a new issue about this, with the same reproduction? Thanks again!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6334 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABEA4EYGRGUTKAIZUGV53A3RWCZZVANCNFSM4NIC4F2Q>
.
--
*Ricco*
*Frontend developer*
|
Updated to rc4 and noticed useQuery was not behaving correctly again - loading always on true when data coming from cache. Downgraded to rc3 and it appears to be working fine. Edit - spoke too soon, rc3 works sometimes but hits the same issue after a few loads! |
Just FYI. (maybe not related) |
I still experience this issue on |
Is this issue solved? |
@MAK-Denis I am also experiencing the same issue on React version 17.0.1 and apollo/client version 3.6.1, any update please |
I somehow found the solution for it, I believe that versino 3.6.0 is very much catered for react 18, which in my case expo's sdk only support up to react 17, therefore using apollo/client: 3.5.4 worked, along with "graphql": "^16.3.0". I hope that helps for u too @MAK-Denis |
@dalley8626 you dirty dog. just saved me days of confusion |
There is an issue with
useQuery
loading state remainingtrue
if a cached query result is displayed and the subsequent variable changes return the same result as the cached one.See codesandbox for the steps to reproduce.
changing the
fetchPolicy
tonetwork-only
orcache-and-network
fixes the issuesThis issues appeared after beta-46 refactor, works as expected in beta-45
Intended outcome:
the
loading
reverts to false once the fetch is finishedActual outcome:
the
loading
staystrue
until the you change the query variable so that the query returns results that are different from the cached one being displayed .How to reproduce the issue:
https://codesandbox.io/s/nifty-ptolemy-1308j?file=/src/App.js
Versions
System:
OS: Windows 10 10.0.19041
Binaries:
Node: 13.8.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files\nodejs\yarn.CMD
npm: 6.13.6 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.19041.1.0
npmPackages:
@apollo/client: ^3.0.0-beta.49 => 3.0.0-beta.50
@apollo/link-error: ^2.0.0-beta.3 => 2.0.0-beta.3
@apollo/link-retry: ^2.0.0-beta.3 => 2.0.0-beta.3
The text was updated successfully, but these errors were encountered: