From 9b06d030825a3c036b9c67b5fb82da9aff638fd3 Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Sun, 12 Apr 2026 18:04:35 -0700 Subject: [PATCH] fix: preserve query behavior during hydration fetch When prefetchInfiniteQuery fails on the server and the promise streams to the client, hydrate() calls query.fetch(undefined, ...) which drops the behavior property. Without infiniteQueryBehavior, the retried fetch stores raw data instead of the expected { pages, pageParams } structure. Pass the query's existing behavior through to the fetch call so infinite queries keep working after hydration. Fixes #8825 --- packages/query-core/src/hydration.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/query-core/src/hydration.ts b/packages/query-core/src/hydration.ts index c75d8ee332c..a893afcb800 100644 --- a/packages/query-core/src/hydration.ts +++ b/packages/query-core/src/hydration.ts @@ -273,10 +273,16 @@ export function hydrate( // Note that we need to call these even when data was synchronously // available, as we still need to set up the retryer query - .fetch(undefined, { - // RSC transformed promises are not thenable - initialPromise: Promise.resolve(promise).then(deserializeData), - }) + .fetch( + // Preserve the query's behavior (e.g. infiniteQueryBehavior) so + // that when the streamed promise resolves, the data gets processed + // through the correct pipeline instead of being stored raw. + query.options.behavior ? { behavior: query.options.behavior } : undefined, + { + // RSC transformed promises are not thenable + initialPromise: Promise.resolve(promise).then(deserializeData), + }, + ) // Avoid unhandled promise rejections .catch(noop) }