@tanstack/query-core 5.0.0-beta.0 → 5.0.0-beta.15
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.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 +3 -3
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +2 -2
- package/build/legacy/infiniteQueryBehavior.d.ts +2 -2
- package/build/legacy/infiniteQueryBehavior.js +3 -3
- package/build/legacy/infiniteQueryBehavior.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +3 -3
- package/build/legacy/infiniteQueryObserver.d.ts +3 -3
- package/build/legacy/infiniteQueryObserver.js.map +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-9264ae39.d.ts → queryClient-58ec0ff3.d.ts} +7 -7
- package/build/legacy/{queryClient-7060338a.d.ts → queryClient-6d6b4ed8.d.ts} +7 -7
- package/build/legacy/queryClient.cjs +1 -3
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +1 -3
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +1 -1
- 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 +1 -1
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/retryer.cjs +1 -1
- 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 +2 -2
- package/build/legacy/retryer.js.map +1 -1
- 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.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 +3 -3
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +2 -2
- package/build/modern/infiniteQueryBehavior.d.ts +2 -2
- package/build/modern/infiniteQueryBehavior.js +3 -3
- package/build/modern/infiniteQueryBehavior.js.map +1 -1
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +3 -3
- package/build/modern/infiniteQueryObserver.d.ts +3 -3
- package/build/modern/infiniteQueryObserver.js.map +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-9264ae39.d.ts → queryClient-58ec0ff3.d.ts} +7 -7
- package/build/modern/{queryClient-7060338a.d.ts → queryClient-6d6b4ed8.d.ts} +7 -7
- package/build/modern/queryClient.cjs +1 -3
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +1 -3
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +1 -1
- 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 +1 -1
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/retryer.cjs +1 -1
- 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 +2 -2
- package/build/modern/retryer.js.map +1 -1
- 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 +7 -3
- package/src/infiniteQueryBehavior.ts +5 -5
- package/src/infiniteQueryObserver.ts +7 -2
- package/src/queryClient.ts +7 -4
- package/src/queryObserver.ts +1 -1
- package/src/retryer.ts +2 -2
- package/src/tests/infiniteQueryObserver.test.tsx +30 -1
- package/src/tests/query.test.tsx +22 -0
- package/src/types.ts +6 -6
package/build/modern/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { aw as CancelOptions, D as DefaultError, av as DefaultOptions, A as DefaultPageParam, J as DefaultedInfiniteQueryObserverOptions, F as DefaultedQueryObserverOptions, ae as DefinedInfiniteQueryObserverResult, a7 as DefinedQueryObserverResult, L as FetchInfiniteQueryOptions, _ as FetchNextPageOptions, $ as FetchPreviousPageOptions, K as FetchQueryOptions, a1 as FetchStatus, v as GetNextPageParamFunction, G as GetPreviousPageParamFunction, w as InfiniteData, a9 as InfiniteQueryObserverBaseResult, ab as InfiniteQueryObserverLoadingErrorResult, aa as InfiniteQueryObserverLoadingResult, H as InfiniteQueryObserverOptions, ac as InfiniteQueryObserverRefetchErrorResult, af as InfiniteQueryObserverResult, ad as InfiniteQueryObserverSuccessResult, B as InfiniteQueryPageParamsOptions, I as InitialDataFunction, Y as InvalidateOptions, V as InvalidateQueryFilters, an as MutateFunction, am as MutateOptions, aj as MutationFunction, ag as MutationKey, ai as MutationMeta, ao as MutationObserverBaseResult, ar as MutationObserverErrorResult, ap as MutationObserverIdleResult, aq as MutationObserverLoadingResult, al as MutationObserverOptions, at as MutationObserverResult, as as MutationObserverSuccessResult, ak as MutationOptions, ah as MutationStatus, N as NetworkMode, az as NotifyEvent, ay as NotifyEventType, y as NotifyOnChangeProps, P as PlaceholderDataFunction, t as QueriesPlaceholderDataFunction, au as QueryClientConfig, q as QueryFunction, s as QueryFunctionContext, p as QueryKey, u as QueryKeyHashFunction, x as QueryMeta, a2 as QueryObserverBaseResult, a4 as QueryObserverLoadingErrorResult, a3 as QueryObserverLoadingResult, E as QueryObserverOptions, a5 as QueryObserverRefetchErrorResult, a8 as QueryObserverResult, a6 as QueryObserverSuccessResult, z as QueryOptions, a0 as QueryStatus, S as RefetchOptions, X as RefetchQueryFilters, R as Register, Z as ResetOptions, O as ResultOptions, ax as SetDataOptions, T as ThrowOnError, W as WithRequired } from './queryClient-
|
|
1
|
+
export { aw as CancelOptions, D as DefaultError, av as DefaultOptions, A as DefaultPageParam, J as DefaultedInfiniteQueryObserverOptions, F as DefaultedQueryObserverOptions, ae as DefinedInfiniteQueryObserverResult, a7 as DefinedQueryObserverResult, L as FetchInfiniteQueryOptions, _ as FetchNextPageOptions, $ as FetchPreviousPageOptions, K as FetchQueryOptions, a1 as FetchStatus, v as GetNextPageParamFunction, G as GetPreviousPageParamFunction, w as InfiniteData, a9 as InfiniteQueryObserverBaseResult, ab as InfiniteQueryObserverLoadingErrorResult, aa as InfiniteQueryObserverLoadingResult, H as InfiniteQueryObserverOptions, ac as InfiniteQueryObserverRefetchErrorResult, af as InfiniteQueryObserverResult, ad as InfiniteQueryObserverSuccessResult, B as InfiniteQueryPageParamsOptions, I as InitialDataFunction, Y as InvalidateOptions, V as InvalidateQueryFilters, an as MutateFunction, am as MutateOptions, aj as MutationFunction, ag as MutationKey, ai as MutationMeta, ao as MutationObserverBaseResult, ar as MutationObserverErrorResult, ap as MutationObserverIdleResult, aq as MutationObserverLoadingResult, al as MutationObserverOptions, at as MutationObserverResult, as as MutationObserverSuccessResult, ak as MutationOptions, ah as MutationStatus, N as NetworkMode, az as NotifyEvent, ay as NotifyEventType, y as NotifyOnChangeProps, P as PlaceholderDataFunction, t as QueriesPlaceholderDataFunction, au as QueryClientConfig, q as QueryFunction, s as QueryFunctionContext, p as QueryKey, u as QueryKeyHashFunction, x as QueryMeta, a2 as QueryObserverBaseResult, a4 as QueryObserverLoadingErrorResult, a3 as QueryObserverLoadingResult, E as QueryObserverOptions, a5 as QueryObserverRefetchErrorResult, a8 as QueryObserverResult, a6 as QueryObserverSuccessResult, z as QueryOptions, a0 as QueryStatus, S as RefetchOptions, X as RefetchQueryFilters, R as Register, Z as ResetOptions, O as ResultOptions, ax as SetDataOptions, T as ThrowOnError, W as WithRequired } from './queryClient-58ec0ff3.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
package/build/modern/utils.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { aD as DataUpdateFunction, e as MutationFilters, f as QueryFilters, aE as QueryTypeFilter, U as Updater, aS as addToEnd, aT as addToStart, aG as functionalUpdate, h as hashKey, aK as hashQueryKeyByOptions, aN as isPlainArray, aO as isPlainObject, i as isServer, aH as isValidTimeout, k as keepPreviousData, aJ as matchMutation, m as matchQuery, aF as noop, aL as partialMatchKey, aR as replaceData, r as replaceEqualDeep, aQ as scheduleMicrotask, aM as shallowEqualObjects, aP as sleep, aI as timeUntilStale } from './queryClient-
|
|
1
|
+
export { aD as DataUpdateFunction, e as MutationFilters, f as QueryFilters, aE as QueryTypeFilter, U as Updater, aS as addToEnd, aT as addToStart, aG as functionalUpdate, h as hashKey, aK as hashQueryKeyByOptions, aN as isPlainArray, aO as isPlainObject, i as isServer, aH as isValidTimeout, k as keepPreviousData, aJ as matchMutation, m as matchQuery, aF as noop, aL as partialMatchKey, aR as replaceData, r as replaceEqualDeep, aQ as scheduleMicrotask, aM as shallowEqualObjects, aP as sleep, aI as timeUntilStale } from './queryClient-6d6b4ed8.js';
|
|
2
2
|
import './removable.cjs';
|
|
3
3
|
import './subscribable.cjs';
|
package/build/modern/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { aD as DataUpdateFunction, e as MutationFilters, f as QueryFilters, aE as QueryTypeFilter, U as Updater, aS as addToEnd, aT as addToStart, aG as functionalUpdate, h as hashKey, aK as hashQueryKeyByOptions, aN as isPlainArray, aO as isPlainObject, i as isServer, aH as isValidTimeout, k as keepPreviousData, aJ as matchMutation, m as matchQuery, aF as noop, aL as partialMatchKey, aR as replaceData, r as replaceEqualDeep, aQ as scheduleMicrotask, aM as shallowEqualObjects, aP as sleep, aI as timeUntilStale } from './queryClient-
|
|
1
|
+
export { aD as DataUpdateFunction, e as MutationFilters, f as QueryFilters, aE as QueryTypeFilter, U as Updater, aS as addToEnd, aT as addToStart, aG as functionalUpdate, h as hashKey, aK as hashQueryKeyByOptions, aN as isPlainArray, aO as isPlainObject, i as isServer, aH as isValidTimeout, k as keepPreviousData, aJ as matchMutation, m as matchQuery, aF as noop, aL as partialMatchKey, aR as replaceData, r as replaceEqualDeep, aQ as scheduleMicrotask, aM as shallowEqualObjects, aP as sleep, aI as timeUntilStale } from './queryClient-58ec0ff3.js';
|
|
2
2
|
import './removable.js';
|
|
3
3
|
import './subscribable.js';
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/query-core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.15",
|
|
4
4
|
"description": "The framework agnostic core that powers TanStack Query",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository":
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TanStack/query.git",
|
|
10
|
+
"directory": "packages/query-core"
|
|
11
|
+
},
|
|
8
12
|
"homepage": "https://tanstack.com/query",
|
|
9
13
|
"funding": {
|
|
10
14
|
"type": "github",
|
|
@@ -38,7 +42,7 @@
|
|
|
38
42
|
"test:types": "tsc",
|
|
39
43
|
"test:lib": "vitest run --coverage",
|
|
40
44
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
41
|
-
"test:build": "publint --strict
|
|
45
|
+
"test:build": "publint --strict",
|
|
42
46
|
"build": "tsup"
|
|
43
47
|
}
|
|
44
48
|
}
|
|
@@ -7,9 +7,9 @@ import type {
|
|
|
7
7
|
QueryKey,
|
|
8
8
|
} from './types'
|
|
9
9
|
|
|
10
|
-
export function infiniteQueryBehavior<TQueryFnData, TError, TData>(
|
|
10
|
+
export function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>(
|
|
11
11
|
pages?: number,
|
|
12
|
-
): QueryBehavior<TQueryFnData, TError, InfiniteData<TData>> {
|
|
12
|
+
): QueryBehavior<TQueryFnData, TError, InfiniteData<TData, TPageParam>> {
|
|
13
13
|
return {
|
|
14
14
|
onFetch: (context) => {
|
|
15
15
|
context.fetchFn = async () => {
|
|
@@ -54,7 +54,7 @@ export function infiniteQueryBehavior<TQueryFnData, TError, TData>(
|
|
|
54
54
|
return Promise.reject()
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
if (
|
|
57
|
+
if (param == null && data.pages.length) {
|
|
58
58
|
return Promise.resolve(data)
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -151,7 +151,7 @@ export function hasNextPage(
|
|
|
151
151
|
data?: InfiniteData<unknown>,
|
|
152
152
|
): boolean {
|
|
153
153
|
if (!data) return false
|
|
154
|
-
return
|
|
154
|
+
return getNextPageParam(options, data) != null
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
/**
|
|
@@ -162,5 +162,5 @@ export function hasPreviousPage(
|
|
|
162
162
|
data?: InfiniteData<unknown>,
|
|
163
163
|
): boolean {
|
|
164
164
|
if (!data || !options.getPreviousPageParam) return false
|
|
165
|
-
return
|
|
165
|
+
return getPreviousPageParam(options, data) != null
|
|
166
166
|
}
|
|
@@ -33,7 +33,7 @@ export class InfiniteQueryObserver<
|
|
|
33
33
|
TQueryFnData,
|
|
34
34
|
TError,
|
|
35
35
|
TData,
|
|
36
|
-
InfiniteData<TQueryData>,
|
|
36
|
+
InfiniteData<TQueryData, TPageParam>,
|
|
37
37
|
TQueryKey
|
|
38
38
|
> {
|
|
39
39
|
// Type override
|
|
@@ -130,7 +130,12 @@ export class InfiniteQueryObserver<
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
protected createResult(
|
|
133
|
-
query: Query<
|
|
133
|
+
query: Query<
|
|
134
|
+
TQueryFnData,
|
|
135
|
+
TError,
|
|
136
|
+
InfiniteData<TQueryData, TPageParam>,
|
|
137
|
+
TQueryKey
|
|
138
|
+
>,
|
|
134
139
|
options: InfiniteQueryObserverOptions<
|
|
135
140
|
TQueryFnData,
|
|
136
141
|
TError,
|
package/src/queryClient.ts
CHANGED
|
@@ -324,10 +324,13 @@ export class QueryClient {
|
|
|
324
324
|
TQueryKey,
|
|
325
325
|
TPageParam
|
|
326
326
|
>,
|
|
327
|
-
): Promise<InfiniteData<TData>> {
|
|
328
|
-
options.behavior = infiniteQueryBehavior<
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
): Promise<InfiniteData<TData, TPageParam>> {
|
|
328
|
+
options.behavior = infiniteQueryBehavior<
|
|
329
|
+
TQueryFnData,
|
|
330
|
+
TError,
|
|
331
|
+
TData,
|
|
332
|
+
TPageParam
|
|
333
|
+
>(options.pages)
|
|
331
334
|
return this.fetchQuery(options)
|
|
332
335
|
}
|
|
333
336
|
|
package/src/queryObserver.ts
CHANGED
|
@@ -763,7 +763,7 @@ function shouldAssignObserverCurrentProperties<
|
|
|
763
763
|
) {
|
|
764
764
|
// if the newly created result isn't what the observer is holding as current,
|
|
765
765
|
// then we'll need to update the properties as well
|
|
766
|
-
if (observer.getCurrentResult()
|
|
766
|
+
if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
|
|
767
767
|
return true
|
|
768
768
|
}
|
|
769
769
|
|
package/src/retryer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { focusManager } from './focusManager'
|
|
2
2
|
import { onlineManager } from './onlineManager'
|
|
3
|
-
import { sleep } from './utils'
|
|
3
|
+
import { isServer, sleep } from './utils'
|
|
4
4
|
import type { CancelOptions, DefaultError, NetworkMode } from './types'
|
|
5
5
|
|
|
6
6
|
// TYPES
|
|
@@ -158,7 +158,7 @@ export function createRetryer<TData = unknown, TError = DefaultError>(
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
// Do we need to retry the request?
|
|
161
|
-
const retry = config.retry ?? 3
|
|
161
|
+
const retry = config.retry ?? (isServer ? 0 : 3)
|
|
162
162
|
const retryDelay = config.retryDelay ?? defaultRetryDelay
|
|
163
163
|
const delay =
|
|
164
164
|
typeof retryDelay === 'function'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { vi } from 'vitest'
|
|
1
|
+
import { expect, vi } from 'vitest'
|
|
2
2
|
import { InfiniteQueryObserver } from '..'
|
|
3
3
|
import { createQueryClient, queryKey, sleep } from './utils'
|
|
4
4
|
import type { QueryClient } from '..'
|
|
@@ -119,6 +119,7 @@ describe('InfiniteQueryObserver', () => {
|
|
|
119
119
|
|
|
120
120
|
expect(observer.getCurrentResult().data?.pages).toEqual(['1', '2'])
|
|
121
121
|
expect(queryFn).toBeCalledTimes(2)
|
|
122
|
+
expect(observer.getCurrentResult().hasNextPage).toBe(true)
|
|
122
123
|
|
|
123
124
|
next = undefined
|
|
124
125
|
|
|
@@ -126,5 +127,33 @@ describe('InfiniteQueryObserver', () => {
|
|
|
126
127
|
|
|
127
128
|
expect(observer.getCurrentResult().data?.pages).toEqual(['1'])
|
|
128
129
|
expect(queryFn).toBeCalledTimes(3)
|
|
130
|
+
expect(observer.getCurrentResult().hasNextPage).toBe(false)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('should stop refetching if null is returned from getNextPageParam', async () => {
|
|
134
|
+
const key = queryKey()
|
|
135
|
+
let next: number | null = 2
|
|
136
|
+
const queryFn = vi.fn<any, any>(({ pageParam }) => String(pageParam))
|
|
137
|
+
const observer = new InfiniteQueryObserver(queryClient, {
|
|
138
|
+
queryKey: key,
|
|
139
|
+
queryFn,
|
|
140
|
+
defaultPageParam: 1,
|
|
141
|
+
getNextPageParam: () => next,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
await observer.fetchNextPage()
|
|
145
|
+
await observer.fetchNextPage()
|
|
146
|
+
|
|
147
|
+
expect(observer.getCurrentResult().data?.pages).toEqual(['1', '2'])
|
|
148
|
+
expect(queryFn).toBeCalledTimes(2)
|
|
149
|
+
expect(observer.getCurrentResult().hasNextPage).toBe(true)
|
|
150
|
+
|
|
151
|
+
next = null
|
|
152
|
+
|
|
153
|
+
await observer.refetch()
|
|
154
|
+
|
|
155
|
+
expect(observer.getCurrentResult().data?.pages).toEqual(['1'])
|
|
156
|
+
expect(queryFn).toBeCalledTimes(3)
|
|
157
|
+
expect(observer.getCurrentResult().hasNextPage).toBe(false)
|
|
129
158
|
})
|
|
130
159
|
})
|
package/src/tests/query.test.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
createQueryClient,
|
|
6
6
|
mockVisibilityState,
|
|
7
7
|
queryKey,
|
|
8
|
+
setIsServer,
|
|
8
9
|
sleep,
|
|
9
10
|
} from './utils'
|
|
10
11
|
import type {
|
|
@@ -804,6 +805,27 @@ describe('query', () => {
|
|
|
804
805
|
consoleMock.mockRestore()
|
|
805
806
|
})
|
|
806
807
|
|
|
808
|
+
it('should not retry on the server', async () => {
|
|
809
|
+
const resetIsServer = setIsServer(true)
|
|
810
|
+
|
|
811
|
+
const key = queryKey()
|
|
812
|
+
let count = 0
|
|
813
|
+
|
|
814
|
+
const observer = new QueryObserver(queryClient, {
|
|
815
|
+
queryKey: key,
|
|
816
|
+
queryFn: () => {
|
|
817
|
+
count++
|
|
818
|
+
return Promise.reject(new Error('error'))
|
|
819
|
+
},
|
|
820
|
+
})
|
|
821
|
+
|
|
822
|
+
await observer.refetch()
|
|
823
|
+
|
|
824
|
+
expect(count).toBe(1)
|
|
825
|
+
|
|
826
|
+
resetIsServer()
|
|
827
|
+
})
|
|
828
|
+
|
|
807
829
|
test('constructor should call initialDataUpdatedAt if defined as a function', async () => {
|
|
808
830
|
const key = queryKey()
|
|
809
831
|
|
package/src/types.ts
CHANGED
|
@@ -71,18 +71,18 @@ export type GetPreviousPageParamFunction<TPageParam, TQueryFnData = unknown> = (
|
|
|
71
71
|
allPages: TQueryFnData[],
|
|
72
72
|
firstPageParam: TPageParam,
|
|
73
73
|
allPageParams: TPageParam[],
|
|
74
|
-
) => TPageParam | undefined
|
|
74
|
+
) => TPageParam | undefined | null
|
|
75
75
|
|
|
76
76
|
export type GetNextPageParamFunction<TPageParam, TQueryFnData = unknown> = (
|
|
77
77
|
lastPage: TQueryFnData,
|
|
78
78
|
allPages: TQueryFnData[],
|
|
79
79
|
lastPageParam: TPageParam,
|
|
80
80
|
allPageParams: TPageParam[],
|
|
81
|
-
) => TPageParam | undefined
|
|
81
|
+
) => TPageParam | undefined | null
|
|
82
82
|
|
|
83
|
-
export interface InfiniteData<TData> {
|
|
83
|
+
export interface InfiniteData<TData, TPageParam = unknown> {
|
|
84
84
|
pages: TData[]
|
|
85
|
-
pageParams:
|
|
85
|
+
pageParams: TPageParam[]
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
export type QueryMeta = Register extends {
|
|
@@ -322,7 +322,7 @@ export interface InfiniteQueryObserverOptions<
|
|
|
322
322
|
TQueryFnData,
|
|
323
323
|
TError,
|
|
324
324
|
TData,
|
|
325
|
-
InfiniteData<TQueryData>,
|
|
325
|
+
InfiniteData<TQueryData, TPageParam>,
|
|
326
326
|
TQueryKey,
|
|
327
327
|
TPageParam
|
|
328
328
|
>,
|
|
@@ -380,7 +380,7 @@ export type FetchInfiniteQueryOptions<
|
|
|
380
380
|
> = FetchQueryOptions<
|
|
381
381
|
TQueryFnData,
|
|
382
382
|
TError,
|
|
383
|
-
InfiniteData<TData>,
|
|
383
|
+
InfiniteData<TData, TPageParam>,
|
|
384
384
|
TQueryKey,
|
|
385
385
|
TPageParam
|
|
386
386
|
> &
|