Skip to content

Commit 7113668

Browse files
committed
Fix bugs
1 parent addb7c1 commit 7113668

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

packages/query-core/src/hydration.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ export function hydrate(
236236
query.setState({
237237
...serializedState,
238238
data,
239+
// if data was resolved synchronously, transition to success
240+
// (mirrors the new-query branch below), but preserve fetchStatus
241+
// if the query is already actively fetching
242+
...(data !== undefined && {
243+
status: 'success' as const,
244+
...(!existingQueryIsFetching && {
245+
fetchStatus: 'idle' as const,
246+
}),
247+
}),
239248
})
240249
}
241250
} else {
@@ -262,6 +271,9 @@ export function hydrate(
262271

263272
if (
264273
promise &&
274+
// If the data was synchronously available, there is no need to set up
275+
// a retryer and thus no reason to call fetch
276+
!syncData &&
265277
!existingQueryIsPending &&
266278
!existingQueryIsFetching &&
267279
// Only hydrate if dehydration is newer than any existing data,
@@ -270,8 +282,6 @@ export function hydrate(
270282
) {
271283
// This doesn't actually fetch - it just creates a retryer
272284
// which will re-use the passed `initialPromise`
273-
// Note that we need to call these even when data was synchronously
274-
// available, as we still need to set up the retryer
275285
query
276286
.fetch(undefined, {
277287
// RSC transformed promises are not thenable

0 commit comments

Comments
 (0)