@tanstack/react-query 5.56.1 → 5.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +2 -2
- package/build/legacy/types.d.ts +2 -2
- package/build/legacy/useBaseQuery.cjs +19 -3
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.d.cts +1 -1
- package/build/legacy/useBaseQuery.d.ts +1 -1
- package/build/legacy/useBaseQuery.js +22 -5
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +2 -2
- package/build/modern/types.d.ts +2 -2
- package/build/modern/useBaseQuery.cjs +18 -2
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.d.cts +1 -1
- package/build/modern/useBaseQuery.d.ts +1 -1
- package/build/modern/useBaseQuery.js +21 -4
- package/build/modern/useBaseQuery.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/prefetch.test.tsx +10 -1
- package/src/__tests__/ssr.test.tsx +4 -2
- package/src/__tests__/suspense.test.tsx +0 -1
- package/src/__tests__/useInfiniteQuery.test.tsx +77 -1
- package/src/__tests__/useQuery.test.tsx +793 -11
- package/src/types.ts +5 -2
- package/src/useBaseQuery.ts +28 -4
package/src/types.ts
CHANGED
|
@@ -101,7 +101,10 @@ export type UseQueryResult<
|
|
|
101
101
|
export type UseSuspenseQueryResult<
|
|
102
102
|
TData = unknown,
|
|
103
103
|
TError = DefaultError,
|
|
104
|
-
> = OmitKeyof<
|
|
104
|
+
> = OmitKeyof<
|
|
105
|
+
DefinedQueryObserverResult<TData, TError>,
|
|
106
|
+
'isPlaceholderData' | 'promise'
|
|
107
|
+
>
|
|
105
108
|
|
|
106
109
|
export type DefinedUseQueryResult<
|
|
107
110
|
TData = unknown,
|
|
@@ -123,7 +126,7 @@ export type UseSuspenseInfiniteQueryResult<
|
|
|
123
126
|
TError = DefaultError,
|
|
124
127
|
> = OmitKeyof<
|
|
125
128
|
DefinedInfiniteQueryObserverResult<TData, TError>,
|
|
126
|
-
'isPlaceholderData'
|
|
129
|
+
'isPlaceholderData' | 'promise'
|
|
127
130
|
>
|
|
128
131
|
|
|
129
132
|
export interface UseMutationOptions<
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
import { notifyManager } from '@tanstack/query-core'
|
|
5
|
-
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'
|
|
4
|
+
import { isServer, notifyManager } from '@tanstack/query-core'
|
|
6
5
|
import { useQueryClient } from './QueryClientProvider'
|
|
7
|
-
import {
|
|
6
|
+
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'
|
|
8
7
|
import {
|
|
9
8
|
ensurePreventErrorBoundaryRetry,
|
|
10
9
|
getHasError,
|
|
11
10
|
useClearResetErrorBoundary,
|
|
12
11
|
} from './errorBoundaryUtils'
|
|
12
|
+
import { useIsRestoring } from './isRestoring'
|
|
13
13
|
import {
|
|
14
14
|
ensureSuspenseTimers,
|
|
15
15
|
fetchOptimistic,
|
|
16
16
|
shouldSuspend,
|
|
17
|
+
willFetch,
|
|
17
18
|
} from './suspense'
|
|
18
|
-
import
|
|
19
|
+
import { noop } from './utils'
|
|
19
20
|
import type {
|
|
20
21
|
QueryClient,
|
|
21
22
|
QueryKey,
|
|
22
23
|
QueryObserver,
|
|
23
24
|
QueryObserverResult,
|
|
24
25
|
} from '@tanstack/query-core'
|
|
26
|
+
import type { UseBaseQueryOptions } from './types'
|
|
25
27
|
|
|
26
28
|
export function useBaseQuery<
|
|
27
29
|
TQueryFnData,
|
|
@@ -67,6 +69,9 @@ export function useBaseQuery<
|
|
|
67
69
|
|
|
68
70
|
useClearResetErrorBoundary(errorResetBoundary)
|
|
69
71
|
|
|
72
|
+
// this needs to be invoked before creating the Observer because that can create a cache entry
|
|
73
|
+
const isNewCacheEntry = !client.getQueryState(options.queryKey)
|
|
74
|
+
|
|
70
75
|
const [observer] = React.useState(
|
|
71
76
|
() =>
|
|
72
77
|
new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(
|
|
@@ -131,6 +136,25 @@ export function useBaseQuery<
|
|
|
131
136
|
result,
|
|
132
137
|
)
|
|
133
138
|
|
|
139
|
+
if (
|
|
140
|
+
defaultedOptions.experimental_prefetchInRender &&
|
|
141
|
+
!isServer &&
|
|
142
|
+
willFetch(result, isRestoring)
|
|
143
|
+
) {
|
|
144
|
+
const promise = isNewCacheEntry
|
|
145
|
+
? // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
|
|
146
|
+
fetchOptimistic(defaultedOptions, observer, errorResetBoundary)
|
|
147
|
+
: // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
|
|
148
|
+
client.getQueryCache().get(defaultedOptions.queryHash)?.promise
|
|
149
|
+
|
|
150
|
+
promise?.catch(noop).finally(() => {
|
|
151
|
+
if (!observer.hasListeners()) {
|
|
152
|
+
// `.updateResult()` will trigger `.#currentThenable` to finalize
|
|
153
|
+
observer.updateResult()
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
134
158
|
// Handle result property usage tracking
|
|
135
159
|
return !defaultedOptions.notifyOnChangeProps
|
|
136
160
|
? observer.trackResult(result)
|