question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Second query in dependent query outputs `status - "success"` before fetching

See original GitHub issue

Subject of the issue

Issue in dependent query fetching,

Even before the second query starts fetching, the status - success is returned

My environment

  • version of react-query - 1.5.3
  • version of next-js - 9.4.2

Steps to reproduce

Issue reproduced in codesandbox - https://codesandbox.io/s/react-query-doubts-j3fhh

Expected behaviour

Second Query should be returning status - loading till the isFetching is done.

Actual behaviour

react-query-issue

Note:

I can directly await for the both the query in the same useQuery, but in my use-case, I have to useQuery to fetch primary data and with the above fetched data as dependency for useInfiniteQuery to get the final data. In the end, I need both primary data and the final data.

Also I cannot await for both the query inside useInfiniteQuery, because I need the data from both the query to be availabe in the resulted data.

But useInfiniteQuery returns an array which becomes hard to get the data from first query.

Also I see that useInfiniteQuery calls the fetchFunction twice during the initial page load during my experiment.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jackmelliscommented, Jun 10, 2020

@tannerlinsley I feel like this is still a bug that doesn’t behave as documented, rather than a general idea that should be addressed at some point in the future…

Surely the expected behaviour here is that the dependent query’s status should be loading until the first query returns truthy?

I have a query that’s never been fetched, and is waiting for some other query to complete, yet the status is success. This doesn’t make sense. It means everywhere I have interdependent queries (which for me is in a lot of places) I have to add multiple other checks and safeguards.

1reaction
tannerlinsleycommented, Jun 2, 2020

Indeed. even with this new issue, my response remains the same. This is something we will have to address in future major (breaking) versions of the library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Second query in dependent query outputs `status - "success ...
I have a query that's never been fetched, and is waiting for some other query to complete, yet the status is success ....
Read more >
How to fetch n dependent data with react-query - Stack Overflow
// It will then go to the `isLoading` stage and hopefully the `isSuccess` stage :) From dependent queries doc. Save this answer. Show...
Read more >
Fetching data with queries | Full-Stack Quickstart
Let's configure that behavior. Merge cached results. Apollo Client stores your query results in its in-memory cache. The cache handles most operations ...
Read more >
useQuery | TanStack Query Docs
The corresponding data property on the query is the data received from the successful fetch or if the query's enabled property is set...
Read more >
Chapter 4. Query Performance Optimization - O'Reilly
Use a covering index (“Using index” in the Extra column) to avoid row accesses, and filter out nonmatching rows after retrieving each result...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found