Prefetching dependent queries with RSC and Suspense #8808
Replies: 1 comment 6 replies
-
if you refetch this query, e.g. via invalidation, it will call the If you don’t want that, you probably don’t need React Query for this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
AFAICT the documentation doesn't cover the case where you want to perform multiple prefetch operations serially in an RSC, because one of the prefetch operations depends on the other.
I struggled to get this working in my app, but I was able to get it working by by forking the Next.js app with prefetching example to add a second query and a
<Suspense>
boundary. Here's the link:HydrationBoundary
)And here's a quick summary:
This works as I'd hoped: Everything outside of the
<Suspense>
boundary renders immediately, and the Suspense-wrapped component doesn't try to render until both pieces of data are available.The only really clunky part is the need for a fake
queryFn
in the firstuseSuspenseQuery
, even if I setstaleTime
toInfinity
. AFAICT there's no way for me to explicitly say "I really only want to get this data on pageload, so I don't need aqueryFn
." Or am I missing something?Update: Looking at this again, there's a bigger issue here: The
queryFn
for the seconduseSuspenseQuery
gets called during SSR. I've filed a bug report: #8828Beta Was this translation helpful? Give feedback.
All reactions