@tanstack/query-core 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/{hydration-D6canbuP.d.cts → hydration-CVKA21uy.d.cts} +53 -0
- package/build/legacy/{hydration-DgUcX5FN.d.ts → hydration-DHZNyHqg.d.ts} +53 -0
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.js +1 -1
- package/build/legacy/infiniteQueryBehavior.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/queriesObserver.d.cts +1 -1
- package/build/legacy/queriesObserver.d.ts +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryObserver.cjs +44 -5
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +45 -6
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/retryer.cjs +7 -11
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/retryer.js +7 -11
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/thenable.cjs +61 -0
- package/build/legacy/thenable.cjs.map +1 -0
- package/build/legacy/thenable.d.cts +36 -0
- package/build/legacy/thenable.d.ts +36 -0
- package/build/legacy/thenable.js +38 -0
- package/build/legacy/thenable.js.map +1 -0
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/modern/{hydration-D6canbuP.d.cts → hydration-CVKA21uy.d.cts} +53 -0
- package/build/modern/{hydration-DgUcX5FN.d.ts → hydration-DHZNyHqg.d.ts} +53 -0
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.cjs +1 -1
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.js +1 -1
- package/build/modern/infiniteQueryBehavior.js.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/queriesObserver.d.cts +1 -1
- package/build/modern/queriesObserver.d.ts +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryObserver.cjs +42 -4
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js +43 -5
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/retryer.cjs +7 -11
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/retryer.js +7 -11
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/thenable.cjs +61 -0
- package/build/modern/thenable.cjs.map +1 -0
- package/build/modern/thenable.d.cts +36 -0
- package/build/modern/thenable.d.ts +36 -0
- package/build/modern/thenable.js +36 -0
- package/build/modern/thenable.js.map +1 -0
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/__tests__/infiniteQueryBehavior.test.tsx +28 -0
- package/src/__tests__/queryObserver.test.tsx +101 -1
- package/src/infiniteQueryBehavior.ts +1 -1
- package/src/queryObserver.ts +63 -4
- package/src/retryer.ts +7 -11
- package/src/thenable.ts +82 -0
- package/src/types.ts +54 -0
package/src/thenable.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thenable types which matches React's types for promises
|
|
3
|
+
*
|
|
4
|
+
* React seemingly uses `.status`, `.value` and `.reason` properties on a promises to optimistically unwrap data from promises
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/facebook/react/blob/main/packages/shared/ReactTypes.js#L112-L138
|
|
7
|
+
* @see https://github.com/facebook/react/blob/4f604941569d2e8947ce1460a0b2997e835f37b9/packages/react-debug-tools/src/ReactDebugHooks.js#L224-L227
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
interface Fulfilled<T> {
|
|
11
|
+
status: 'fulfilled'
|
|
12
|
+
value: T
|
|
13
|
+
}
|
|
14
|
+
interface Rejected {
|
|
15
|
+
status: 'rejected'
|
|
16
|
+
reason: unknown
|
|
17
|
+
}
|
|
18
|
+
interface Pending<T> {
|
|
19
|
+
status: 'pending'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the promise with a value.
|
|
23
|
+
* Will remove the `resolve` and `reject` properties from the promise.
|
|
24
|
+
*/
|
|
25
|
+
resolve: (value: T) => void
|
|
26
|
+
/**
|
|
27
|
+
* Reject the promise with a reason.
|
|
28
|
+
* Will remove the `resolve` and `reject` properties from the promise.
|
|
29
|
+
*/
|
|
30
|
+
reject: (reason: unknown) => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type FulfilledThenable<T> = Promise<T> & Fulfilled<T>
|
|
34
|
+
export type RejectedThenable<T> = Promise<T> & Rejected
|
|
35
|
+
export type PendingThenable<T> = Promise<T> & Pending<T>
|
|
36
|
+
|
|
37
|
+
export type Thenable<T> =
|
|
38
|
+
| FulfilledThenable<T>
|
|
39
|
+
| RejectedThenable<T>
|
|
40
|
+
| PendingThenable<T>
|
|
41
|
+
|
|
42
|
+
export function pendingThenable<T>(): PendingThenable<T> {
|
|
43
|
+
let resolve: Pending<T>['resolve']
|
|
44
|
+
let reject: Pending<T>['reject']
|
|
45
|
+
// this could use `Promise.withResolvers()` in the future
|
|
46
|
+
const thenable = new Promise((_resolve, _reject) => {
|
|
47
|
+
resolve = _resolve
|
|
48
|
+
reject = _reject
|
|
49
|
+
}) as PendingThenable<T>
|
|
50
|
+
|
|
51
|
+
thenable.status = 'pending'
|
|
52
|
+
thenable.catch(() => {
|
|
53
|
+
// prevent unhandled rejection errors
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
function finalize(data: Fulfilled<T> | Rejected) {
|
|
57
|
+
Object.assign(thenable, data)
|
|
58
|
+
|
|
59
|
+
// clear pending props props to avoid calling them twice
|
|
60
|
+
delete (thenable as Partial<PendingThenable<T>>).resolve
|
|
61
|
+
delete (thenable as Partial<PendingThenable<T>>).reject
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
thenable.resolve = (value) => {
|
|
65
|
+
finalize({
|
|
66
|
+
status: 'fulfilled',
|
|
67
|
+
value,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
resolve(value)
|
|
71
|
+
}
|
|
72
|
+
thenable.reject = (reason) => {
|
|
73
|
+
finalize({
|
|
74
|
+
status: 'rejected',
|
|
75
|
+
reason,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
reject(reason)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return thenable
|
|
82
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -380,6 +380,11 @@ export interface QueryObserverOptions<
|
|
|
380
380
|
>
|
|
381
381
|
|
|
382
382
|
_optimisticResults?: 'optimistic' | 'isRestoring'
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Enable prefetching during rendering
|
|
386
|
+
*/
|
|
387
|
+
experimental_prefetchInRender?: boolean
|
|
383
388
|
}
|
|
384
389
|
|
|
385
390
|
export type WithRequired<TTarget, TKey extends keyof TTarget> = TTarget & {
|
|
@@ -687,6 +692,55 @@ export interface QueryObserverBaseResult<
|
|
|
687
692
|
* - See [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
|
|
688
693
|
*/
|
|
689
694
|
fetchStatus: FetchStatus
|
|
695
|
+
/**
|
|
696
|
+
* A stable promise that will be resolved with the data of the query.
|
|
697
|
+
* Requires the `experimental_prefetchInRender` feature flag to be enabled.
|
|
698
|
+
* @example
|
|
699
|
+
*
|
|
700
|
+
* ### Enabling the feature flag
|
|
701
|
+
* ```ts
|
|
702
|
+
* const client = new QueryClient({
|
|
703
|
+
* defaultOptions: {
|
|
704
|
+
* queries: {
|
|
705
|
+
* experimental_prefetchInRender: true,
|
|
706
|
+
* },
|
|
707
|
+
* },
|
|
708
|
+
* })
|
|
709
|
+
* ```
|
|
710
|
+
*
|
|
711
|
+
* ### Usage
|
|
712
|
+
* ```tsx
|
|
713
|
+
* import { useQuery } from '@tanstack/react-query'
|
|
714
|
+
* import React from 'react'
|
|
715
|
+
* import { fetchTodos, type Todo } from './api'
|
|
716
|
+
*
|
|
717
|
+
* function TodoList({ query }: { query: UseQueryResult<Todo[], Error> }) {
|
|
718
|
+
* const data = React.use(query.promise)
|
|
719
|
+
*
|
|
720
|
+
* return (
|
|
721
|
+
* <ul>
|
|
722
|
+
* {data.map(todo => (
|
|
723
|
+
* <li key={todo.id}>{todo.title}</li>
|
|
724
|
+
* ))}
|
|
725
|
+
* </ul>
|
|
726
|
+
* )
|
|
727
|
+
* }
|
|
728
|
+
*
|
|
729
|
+
* export function App() {
|
|
730
|
+
* const query = useQuery({ queryKey: ['todos'], queryFn: fetchTodos })
|
|
731
|
+
*
|
|
732
|
+
* return (
|
|
733
|
+
* <>
|
|
734
|
+
* <h1>Todos</h1>
|
|
735
|
+
* <React.Suspense fallback={<div>Loading...</div>}>
|
|
736
|
+
* <TodoList query={query} />
|
|
737
|
+
* </React.Suspense>
|
|
738
|
+
* </>
|
|
739
|
+
* )
|
|
740
|
+
* }
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
promise: Promise<TData>
|
|
690
744
|
}
|
|
691
745
|
|
|
692
746
|
export interface QueryObserverPendingResult<
|