-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(react-query): non continuous suspense with useSuspenseQueries (#6298) #6303
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d3acc6f:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this fix in mind:
Subject: [PATCH] fix: useQueries suspense
---
Index: packages/react-query/src/useQueries.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/packages/react-query/src/useQueries.ts b/packages/react-query/src/useQueries.ts
--- a/packages/react-query/src/useQueries.ts
+++ b/packages/react-query/src/useQueries.ts
@@ -1,7 +1,11 @@
'use client'
import * as React from 'react'
-import { QueriesObserver, notifyManager } from '@tanstack/query-core'
+import {
+ QueriesObserver,
+ QueryObserver,
+ notifyManager,
+} from '@tanstack/query-core'
import { useQueryClient } from './QueryClientProvider'
import { useIsRestoring } from './isRestoring'
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'
@@ -262,9 +266,9 @@
const suspensePromises = shouldAtLeastOneSuspend
? optimisticResult.flatMap((result, index) => {
const opts = defaultedQueries[index]
- const queryObserver = observer.getObservers()[index]
- if (opts && queryObserver) {
+ if (opts) {
+ const queryObserver = new QueryObserver(client, opts)
if (shouldSuspend(opts, result, isRestoring)) {
return fetchOptimistic(opts, queryObserver, errorResetBoundary)
} else if (willFetch(result, isRestoring)) {
I think we don't need to use the matching observer on the QueriesObserver - the fetch is fire-and-forget anyways, so I just created a new QueryObserver
to do the fetch.
the fetchOptimistic
method on the observer is just a small wrapper around query.fetch()
, so we technically don't even need it ... but changing that could be considered breaking, so this is the most minimal fix I could find. Can you try if your tests also work with that solution?
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d3acc6f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
Nice and simple. |
There are some warnings with the way the tests are written:
maybe relates to: not sure if we'd need to update testing-library or vitest or both? Maybe you could also change the tests to be written more like the other tests that we have? We basically don't test hooks, but wrap them in components like so: query/packages/react-query/src/__tests__/suspense.test.tsx Lines 123 to 148 in c014ea7
|
Happy to comply. |
Codecov ReportAll modified and coverable lines are covered by tests ✅ ❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
... and 67 files with indirect coverage changes 📢 Thoughts on this report? Let us know!. |
…nStack#6298) (TanStack#6303) Co-authored-by: Dominik Dorfmeister <[email protected]>
#6298