-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Allow intersecting stale results #168
base: main
Are you sure you want to change the base?
Conversation
When the "intersectStaleData" flag is passed, the returned data of the queries will also be intersected if every query has data.
When the "intersectStaleData" flag is passed, the returned data of the queries will also be intersected if every query has data.
Run & review this pull request in StackBlitz Codeflow. |
Can you explain the use case, please? |
Sure! If previous fetches were successful, the query library returns data even if the last fetch failed due to an error. We use this feature extensively to show data to the user even if it is stale, for example due to a bad internet connection. The data does not even need to be stale if the query was not yet invalidated but triggered again via refetch. With the intersectResults functionality, so far we lose that feature - only if all queries are successful, data is returned. I think this kind of breaks the contract of the @tanstack/query interface. While I'm writing about it - I think the "isStale" flag from the tanstack interface should also be added. |
@NetanelBasal Do you think this change is counterproductive? |
Yes, I don't know it this is always the expected behaviour. It feels like Promise.allSettled a little bit |
Yes, it feels a bit similar to Promise.allSettled. I think that is a useful behavior. If I have a normal query (not intersected), as long I have cached results I get data even if the latest fetch failed and I can display that data (maybe display some information that it is stale via the isStale flag and so on, you can see the flag description here: https://tanstack.com/query/latest/docs/framework/react/reference/useQuery). With the current implementation of intersectResults, I get only data if the latest fetch for all intersected queries was successful and only in this case I can display data. We currently implemented this utility in our own code, I just thought it might be useful for others as well. Of course, if you think it should not be in the library, feel free to close the PR. |
I will leave the PR open and see if anyone else wants this functionality. Thanks. |
This change allows intersecting not only current, but also stale data from multiple queries.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
At the moment, the data is only intersected if all queries are successful.
Issue Number: N/A
What is the new behavior?
If an option is passed, data will also returned if all queries contain data (stale or current).
Does this PR introduce a breaking change?