Replies: 2 comments 1 reply
-
|
streaming doesn’t yet work with infinite queries: |
Beta Was this translation helpful? Give feedback.
-
|
The root cause here is that your Here's what happens step by step:
The fix: await your prefetches and catch auth failures Update export const ServerFetchBoundary = async ({
children,
queryOptions,
infiniteQueryOptions,
}: ServerFetchBoundaryProps) => {
await connection();
const queryClient = getQueryClient();
const queries = queryOptions
? Array.isArray(queryOptions) ? queryOptions : [queryOptions]
: [];
const infiniteQueries = infiniteQueryOptions
? Array.isArray(infiniteQueryOptions) ? infiniteQueryOptions : [infiniteQueryOptions]
: [];
await Promise.all([
...queries.map(opt => queryClient.prefetchQuery(opt).catch(() => {})),
...infiniteQueries.map(opt => queryClient.prefetchInfiniteQuery(opt).catch(() => {})),
]);
return <HydrationBoundary state={dehydrate(queryClient)}>{children}</HydrationBoundary>;
};The
This avoids the streaming path entirely for all these queries, which is exactly TkDodo's recommended workaround: "don't stream promises for infinite queries, but await them on the server." Why not just make getNextPageParam: (lastPage: FeedListResponse | undefined) =>
lastPage?.hasNext ? lastPage.cursor : undefined,This silences the crash but doesn't fix the underlying data structure problem — the client is still working with a malformed query state that'll cause other subtle issues. The upstream fix for the streaming case is being tracked in PR #9633 if you need that path later. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I’m learning TanStack Query.
I ran into an issue when testing Server Components(Next.js 16, app router) with missing access tokens:
Situation:
Question:
How should I handle prefetchInfiniteQuery in Server Components so that the client can safely continue infinite queries even if the server throws an error?
Relevant Code:
page.tsx
client component
queryOptions
ServerFetchBoundary.tsx
queryClientOption
Is there a recommended way to handle prefetchInfiniteQuery in Server Components so that the client can safely continue infiniteQuery fetching even when the server throws an error?
Thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions