@tanstack/query-core 5.51.1 → 5.51.4
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-ByKLEQMr.d.ts → hydration-B_q3JSpO.d.ts} +5 -5
- package/build/legacy/{hydration-DfqGmvZi.d.cts → hydration-BtJW-7io.d.cts} +5 -5
- 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 -9
- 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 +3 -9
- 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.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/utils.cjs +4 -4
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js +4 -4
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/{hydration-ByKLEQMr.d.ts → hydration-B_q3JSpO.d.ts} +5 -5
- package/build/modern/{hydration-DfqGmvZi.d.cts → hydration-BtJW-7io.d.cts} +5 -5
- 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 -8
- 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 +3 -8
- 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.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/utils.cjs +4 -4
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js +4 -4
- package/build/modern/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/hydration.test.tsx +4 -2
- package/src/__tests__/infiniteQueryObserver.test.tsx +41 -2
- package/src/__tests__/query.test.tsx +15 -11
- package/src/__tests__/queryClient.test.tsx +96 -32
- package/src/__tests__/queryObserver.test.tsx +24 -8
- package/src/__tests__/utils.ts +4 -4
- package/src/infiniteQueryBehavior.ts +11 -12
- package/src/utils.ts +4 -4
|
@@ -26,7 +26,9 @@ describe('queryObserver', () => {
|
|
|
26
26
|
|
|
27
27
|
test('should trigger a fetch when subscribed', async () => {
|
|
28
28
|
const key = queryKey()
|
|
29
|
-
const queryFn = vi
|
|
29
|
+
const queryFn = vi
|
|
30
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
31
|
+
.mockReturnValue('data')
|
|
30
32
|
const observer = new QueryObserver(queryClient, { queryKey: key, queryFn })
|
|
31
33
|
const unsubscribe = observer.subscribe(() => undefined)
|
|
32
34
|
await sleep(1)
|
|
@@ -584,7 +586,9 @@ describe('queryObserver', () => {
|
|
|
584
586
|
|
|
585
587
|
test('should not trigger a fetch when subscribed and disabled', async () => {
|
|
586
588
|
const key = queryKey()
|
|
587
|
-
const queryFn = vi
|
|
589
|
+
const queryFn = vi
|
|
590
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
591
|
+
.mockReturnValue('data')
|
|
588
592
|
const observer = new QueryObserver(queryClient, {
|
|
589
593
|
queryKey: key,
|
|
590
594
|
queryFn,
|
|
@@ -598,7 +602,9 @@ describe('queryObserver', () => {
|
|
|
598
602
|
|
|
599
603
|
test('should not trigger a fetch when subscribed and disabled by callback', async () => {
|
|
600
604
|
const key = queryKey()
|
|
601
|
-
const queryFn = vi
|
|
605
|
+
const queryFn = vi
|
|
606
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
607
|
+
.mockReturnValue('data')
|
|
602
608
|
const observer = new QueryObserver(queryClient, {
|
|
603
609
|
queryKey: key,
|
|
604
610
|
queryFn,
|
|
@@ -612,7 +618,9 @@ describe('queryObserver', () => {
|
|
|
612
618
|
|
|
613
619
|
test('should not trigger a fetch when not subscribed', async () => {
|
|
614
620
|
const key = queryKey()
|
|
615
|
-
const queryFn = vi
|
|
621
|
+
const queryFn = vi
|
|
622
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
623
|
+
.mockReturnValue('data')
|
|
616
624
|
new QueryObserver(queryClient, { queryKey: key, queryFn })
|
|
617
625
|
await sleep(1)
|
|
618
626
|
expect(queryFn).toHaveBeenCalledTimes(0)
|
|
@@ -620,7 +628,9 @@ describe('queryObserver', () => {
|
|
|
620
628
|
|
|
621
629
|
test('should be able to watch a query without defining a query function', async () => {
|
|
622
630
|
const key = queryKey()
|
|
623
|
-
const queryFn = vi
|
|
631
|
+
const queryFn = vi
|
|
632
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
633
|
+
.mockReturnValue('data')
|
|
624
634
|
const callback = vi.fn()
|
|
625
635
|
const observer = new QueryObserver(queryClient, {
|
|
626
636
|
queryKey: key,
|
|
@@ -635,7 +645,9 @@ describe('queryObserver', () => {
|
|
|
635
645
|
|
|
636
646
|
test('should accept unresolved query config in update function', async () => {
|
|
637
647
|
const key = queryKey()
|
|
638
|
-
const queryFn = vi
|
|
648
|
+
const queryFn = vi
|
|
649
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
650
|
+
.mockReturnValue('data')
|
|
639
651
|
const observer = new QueryObserver(queryClient, {
|
|
640
652
|
queryKey: key,
|
|
641
653
|
enabled: false,
|
|
@@ -656,7 +668,9 @@ describe('queryObserver', () => {
|
|
|
656
668
|
|
|
657
669
|
test('should be able to handle multiple subscribers', async () => {
|
|
658
670
|
const key = queryKey()
|
|
659
|
-
const queryFn = vi
|
|
671
|
+
const queryFn = vi
|
|
672
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
673
|
+
.mockReturnValue('data')
|
|
660
674
|
const observer = new QueryObserver<string>(queryClient, {
|
|
661
675
|
queryKey: key,
|
|
662
676
|
enabled: false,
|
|
@@ -816,7 +830,9 @@ describe('queryObserver', () => {
|
|
|
816
830
|
|
|
817
831
|
test('should not refetch in background if refetchIntervalInBackground is false', async () => {
|
|
818
832
|
const key = queryKey()
|
|
819
|
-
const queryFn = vi
|
|
833
|
+
const queryFn = vi
|
|
834
|
+
.fn<(...args: Array<unknown>) => string>()
|
|
835
|
+
.mockReturnValue('data')
|
|
820
836
|
|
|
821
837
|
focusManager.setFocused(false)
|
|
822
838
|
const observer = new QueryObserver(queryClient, {
|
package/src/__tests__/utils.ts
CHANGED
|
@@ -10,13 +10,13 @@ export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
|
10
10
|
|
|
11
11
|
export function mockVisibilityState(
|
|
12
12
|
value: DocumentVisibilityState,
|
|
13
|
-
): MockInstance<
|
|
13
|
+
): MockInstance<() => DocumentVisibilityState> {
|
|
14
14
|
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function mockOnlineManagerIsOnline(
|
|
18
18
|
value: boolean,
|
|
19
|
-
): MockInstance<
|
|
19
|
+
): MockInstance<() => boolean> {
|
|
20
20
|
return vi.spyOn(onlineManager, 'isOnline').mockReturnValue(value)
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -32,11 +32,11 @@ export function sleep(timeout: number): Promise<void> {
|
|
|
32
32
|
})
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export
|
|
35
|
+
export function executeMutation<TVariables>(
|
|
36
36
|
queryClient: QueryClient,
|
|
37
37
|
options: MutationOptions<any, any, TVariables, any>,
|
|
38
38
|
variables: TVariables,
|
|
39
|
-
)
|
|
39
|
+
) {
|
|
40
40
|
return queryClient
|
|
41
41
|
.getMutationCache()
|
|
42
42
|
.build(queryClient, options)
|
|
@@ -133,24 +133,23 @@ function getNextPageParam(
|
|
|
133
133
|
{ pages, pageParams }: InfiniteData<unknown>,
|
|
134
134
|
): unknown | undefined {
|
|
135
135
|
const lastIndex = pages.length - 1
|
|
136
|
-
return
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
136
|
+
return pages.length > 0
|
|
137
|
+
? options.getNextPageParam(
|
|
138
|
+
pages[lastIndex],
|
|
139
|
+
pages,
|
|
140
|
+
pageParams[lastIndex],
|
|
141
|
+
pageParams,
|
|
142
|
+
)
|
|
143
|
+
: undefined
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
function getPreviousPageParam(
|
|
145
147
|
options: InfiniteQueryPageParamsOptions<any>,
|
|
146
148
|
{ pages, pageParams }: InfiniteData<unknown>,
|
|
147
149
|
): unknown | undefined {
|
|
148
|
-
return
|
|
149
|
-
pages[0],
|
|
150
|
-
|
|
151
|
-
pageParams[0],
|
|
152
|
-
pageParams,
|
|
153
|
-
)
|
|
150
|
+
return pages.length > 0
|
|
151
|
+
? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams)
|
|
152
|
+
: undefined
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
/**
|
package/src/utils.ts
CHANGED
|
@@ -340,9 +340,9 @@ function hasObjectPrototype(o: any): boolean {
|
|
|
340
340
|
return Object.prototype.toString.call(o) === '[object Object]'
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
export function sleep(
|
|
343
|
+
export function sleep(timeout: number): Promise<void> {
|
|
344
344
|
return new Promise((resolve) => {
|
|
345
|
-
setTimeout(resolve,
|
|
345
|
+
setTimeout(resolve, timeout)
|
|
346
346
|
})
|
|
347
347
|
}
|
|
348
348
|
|
|
@@ -378,7 +378,7 @@ export function addToStart<T>(items: Array<T>, item: T, max = 0): Array<T> {
|
|
|
378
378
|
export const skipToken = Symbol()
|
|
379
379
|
export type SkipToken = typeof skipToken
|
|
380
380
|
|
|
381
|
-
export
|
|
381
|
+
export function ensureQueryFn<
|
|
382
382
|
TQueryFnData = unknown,
|
|
383
383
|
TQueryKey extends QueryKey = QueryKey,
|
|
384
384
|
>(
|
|
@@ -387,7 +387,7 @@ export const ensureQueryFn = <
|
|
|
387
387
|
queryHash?: string
|
|
388
388
|
},
|
|
389
389
|
fetchOptions?: FetchOptions<TQueryFnData>,
|
|
390
|
-
): QueryFunction<TQueryFnData, TQueryKey>
|
|
390
|
+
): QueryFunction<TQueryFnData, TQueryKey> {
|
|
391
391
|
if (process.env.NODE_ENV !== 'production') {
|
|
392
392
|
if (options.queryFn === skipToken) {
|
|
393
393
|
console.error(
|