@tanstack/react-query 5.0.0-alpha.81 → 5.0.0-alpha.85
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/lib/HydrationBoundary.cjs.map +1 -1
- package/build/lib/HydrationBoundary.d.ts.map +1 -1
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/HydrationBoundary.legacy.cjs.map +1 -1
- package/build/lib/HydrationBoundary.legacy.js.map +1 -1
- package/build/lib/__tests__/utils.d.ts +4 -3
- package/build/lib/__tests__/utils.d.ts.map +1 -1
- package/build/lib/errorBoundaryUtils.cjs.map +1 -1
- package/build/lib/errorBoundaryUtils.d.ts.map +1 -1
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/errorBoundaryUtils.legacy.cjs.map +1 -1
- package/build/lib/errorBoundaryUtils.legacy.js.map +1 -1
- package/build/lib/suspense.cjs.map +1 -1
- package/build/lib/suspense.d.ts +1 -1
- package/build/lib/suspense.d.ts.map +1 -1
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/suspense.legacy.cjs.map +1 -1
- package/build/lib/suspense.legacy.js.map +1 -1
- package/build/lib/types.d.ts +1 -1
- package/build/lib/types.d.ts.map +1 -1
- package/build/lib/useBaseQuery.cjs.map +1 -1
- package/build/lib/useBaseQuery.d.ts +1 -1
- package/build/lib/useBaseQuery.d.ts.map +1 -1
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.legacy.cjs.map +1 -1
- package/build/lib/useBaseQuery.legacy.js.map +1 -1
- package/build/lib/useInfiniteQuery.cjs.map +1 -1
- package/build/lib/useInfiniteQuery.d.ts +1 -1
- package/build/lib/useInfiniteQuery.d.ts.map +1 -1
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.legacy.cjs.map +1 -1
- package/build/lib/useInfiniteQuery.legacy.js.map +1 -1
- package/build/lib/useIsFetching.cjs.map +1 -1
- package/build/lib/useIsFetching.d.ts.map +1 -1
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.legacy.cjs.map +1 -1
- package/build/lib/useIsFetching.legacy.js.map +1 -1
- package/build/lib/useMutation.cjs.map +1 -1
- package/build/lib/useMutation.d.ts +1 -1
- package/build/lib/useMutation.d.ts.map +1 -1
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.legacy.cjs.map +1 -1
- package/build/lib/useMutation.legacy.js.map +1 -1
- package/build/lib/useMutationState.cjs.map +1 -1
- package/build/lib/useMutationState.d.ts +1 -1
- package/build/lib/useMutationState.d.ts.map +1 -1
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useMutationState.legacy.cjs.map +1 -1
- package/build/lib/useMutationState.legacy.js.map +1 -1
- package/build/lib/useQueries.cjs.map +1 -1
- package/build/lib/useQueries.d.ts +1 -1
- package/build/lib/useQueries.d.ts.map +1 -1
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.legacy.cjs.map +1 -1
- package/build/lib/useQueries.legacy.js.map +1 -1
- package/build/lib/useQuery.cjs.map +1 -1
- package/build/lib/useQuery.d.ts +1 -1
- package/build/lib/useQuery.d.ts.map +1 -1
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.legacy.cjs.map +1 -1
- package/build/lib/useQuery.legacy.js.map +1 -1
- package/package.json +2 -2
- package/src/HydrationBoundary.tsx +1 -1
- package/src/__tests__/HydrationBoundary.test.tsx +5 -5
- package/src/__tests__/QueryClientProvider.test.tsx +2 -2
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +2 -2
- package/src/__tests__/ssr-hydration.test.tsx +2 -2
- package/src/__tests__/ssr.test.tsx +2 -2
- package/src/__tests__/suspense.test.tsx +2 -2
- package/src/__tests__/useInfiniteQuery.test.tsx +2 -2
- package/src/__tests__/useInfiniteQuery.type.test.tsx +2 -2
- package/src/__tests__/useIsFetching.test.tsx +1 -1
- package/src/__tests__/useMutation.test.tsx +2 -2
- package/src/__tests__/useQueries.test.tsx +8 -8
- package/src/__tests__/useQuery.test.tsx +14 -13
- package/src/__tests__/useQuery.types.test.tsx +1 -1
- package/src/__tests__/utils.tsx +7 -4
- package/src/errorBoundaryUtils.ts +2 -2
- package/src/suspense.ts +1 -1
- package/src/types.ts +5 -5
- package/src/useBaseQuery.ts +3 -3
- package/src/useInfiniteQuery.ts +5 -5
- package/src/useIsFetching.ts +1 -1
- package/src/useMutation.ts +3 -3
- package/src/useMutationState.ts +5 -5
- package/src/useQueries.ts +11 -11
- package/src/useQuery.ts +2 -2
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { act, fireEvent, render, waitFor } from '@testing-library/react'
|
|
2
2
|
import '@testing-library/jest-dom'
|
|
3
3
|
import * as React from 'react'
|
|
4
|
+
import { ErrorBoundary } from 'react-error-boundary'
|
|
5
|
+
import { vi } from 'vitest'
|
|
6
|
+
import { QueryCache, keepPreviousData, useQuery } from '..'
|
|
4
7
|
import {
|
|
5
8
|
Blink,
|
|
6
9
|
createQueryClient,
|
|
@@ -19,9 +22,6 @@ import type {
|
|
|
19
22
|
UseQueryOptions,
|
|
20
23
|
UseQueryResult,
|
|
21
24
|
} from '..'
|
|
22
|
-
import { QueryCache, useQuery, keepPreviousData } from '..'
|
|
23
|
-
import { ErrorBoundary } from 'react-error-boundary'
|
|
24
|
-
import { vi } from 'vitest'
|
|
25
25
|
import type { Mock } from 'vitest'
|
|
26
26
|
|
|
27
27
|
describe('useQuery', () => {
|
|
@@ -2603,24 +2603,24 @@ describe('useQuery', () => {
|
|
|
2603
2603
|
refetchOnWindowFocus: 'always',
|
|
2604
2604
|
})
|
|
2605
2605
|
states.push(state)
|
|
2606
|
-
return
|
|
2606
|
+
return (
|
|
2607
|
+
<div>
|
|
2608
|
+
<div>
|
|
2609
|
+
data: {state.data}, isFetching: {String(state.isFetching)}
|
|
2610
|
+
</div>
|
|
2611
|
+
</div>
|
|
2612
|
+
)
|
|
2607
2613
|
}
|
|
2608
2614
|
|
|
2609
|
-
renderWithClient(queryClient, <Page />)
|
|
2615
|
+
const rendered = renderWithClient(queryClient, <Page />)
|
|
2610
2616
|
|
|
2611
|
-
await
|
|
2617
|
+
await waitFor(() => rendered.getByText('data: 0, isFetching: false'))
|
|
2612
2618
|
|
|
2613
2619
|
act(() => {
|
|
2614
2620
|
window.dispatchEvent(new Event('visibilitychange'))
|
|
2615
2621
|
})
|
|
2616
2622
|
|
|
2617
|
-
await
|
|
2618
|
-
|
|
2619
|
-
await waitFor(() => expect(states.length).toBe(4))
|
|
2620
|
-
expect(states[0]).toMatchObject({ data: undefined, isFetching: true })
|
|
2621
|
-
expect(states[1]).toMatchObject({ data: 0, isFetching: false })
|
|
2622
|
-
expect(states[2]).toMatchObject({ data: 0, isFetching: true })
|
|
2623
|
-
expect(states[3]).toMatchObject({ data: 1, isFetching: false })
|
|
2623
|
+
await waitFor(() => rendered.getByText('data: 1, isFetching: false'))
|
|
2624
2624
|
})
|
|
2625
2625
|
|
|
2626
2626
|
it('should calculate focus behaviour for `refetchOnWindowFocus` depending on function', async () => {
|
|
@@ -5458,6 +5458,7 @@ describe('useQuery', () => {
|
|
|
5458
5458
|
await waitFor(() => rendered.getByText('failureReason: failed1'))
|
|
5459
5459
|
|
|
5460
5460
|
const onlineMock = mockNavigatorOnLine(false)
|
|
5461
|
+
window.dispatchEvent(new Event('offline'))
|
|
5461
5462
|
|
|
5462
5463
|
await sleep(20)
|
|
5463
5464
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useQuery } from '../useQuery'
|
|
2
2
|
import { queryOptions } from '../queryOptions'
|
|
3
|
-
import type { Expect, Equal } from './utils'
|
|
4
3
|
import { doNotExecute } from './utils'
|
|
4
|
+
import type { Equal, Expect } from './utils'
|
|
5
5
|
|
|
6
6
|
describe('initialData', () => {
|
|
7
7
|
describe('Config object overload', () => {
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { act, render } from '@testing-library/react'
|
|
3
|
-
import type { QueryClientConfig } from '..'
|
|
4
|
-
import { QueryClient, QueryClientProvider } from '..'
|
|
5
3
|
import * as utils from '@tanstack/query-core'
|
|
6
4
|
import { vi } from 'vitest'
|
|
5
|
+
import { QueryClient, QueryClientProvider } from '..'
|
|
6
|
+
import type { QueryClientConfig } from '..'
|
|
7
|
+
import type { SpyInstance } from 'vitest'
|
|
7
8
|
|
|
8
9
|
export function renderWithClient(
|
|
9
10
|
client: QueryClient,
|
|
@@ -45,11 +46,13 @@ export function createQueryClient(config?: QueryClientConfig): QueryClient {
|
|
|
45
46
|
return new QueryClient(config)
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
export function mockVisibilityState(
|
|
49
|
+
export function mockVisibilityState(
|
|
50
|
+
value: DocumentVisibilityState,
|
|
51
|
+
): SpyInstance<[], DocumentVisibilityState> {
|
|
49
52
|
return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
export function mockNavigatorOnLine(value: boolean) {
|
|
55
|
+
export function mockNavigatorOnLine(value: boolean): SpyInstance<[], boolean> {
|
|
53
56
|
return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { shouldThrowError } from './utils'
|
|
2
4
|
import type {
|
|
3
5
|
DefaultedQueryObserverOptions,
|
|
4
6
|
Query,
|
|
@@ -7,8 +9,6 @@ import type {
|
|
|
7
9
|
ThrowOnError,
|
|
8
10
|
} from '@tanstack/query-core'
|
|
9
11
|
import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
|
|
10
|
-
import * as React from 'react'
|
|
11
|
-
import { shouldThrowError } from './utils'
|
|
12
12
|
|
|
13
13
|
export const ensurePreventErrorBoundaryRetry = <
|
|
14
14
|
TQueryFnData,
|
package/src/suspense.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/* istanbul ignore file */
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
+
DefaultError,
|
|
5
|
+
DefinedQueryObserverResult,
|
|
4
6
|
InfiniteQueryObserverOptions,
|
|
5
7
|
InfiniteQueryObserverResult,
|
|
8
|
+
MutateFunction,
|
|
9
|
+
MutationObserverOptions,
|
|
6
10
|
MutationObserverResult,
|
|
11
|
+
QueryKey,
|
|
7
12
|
QueryObserverOptions,
|
|
8
13
|
QueryObserverResult,
|
|
9
|
-
QueryKey,
|
|
10
|
-
MutationObserverOptions,
|
|
11
|
-
MutateFunction,
|
|
12
|
-
DefinedQueryObserverResult,
|
|
13
14
|
WithRequired,
|
|
14
|
-
DefaultError,
|
|
15
15
|
} from '@tanstack/query-core'
|
|
16
16
|
|
|
17
17
|
export interface UseBaseQueryOptions<
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'
|
|
5
4
|
import { notifyManager } from '@tanstack/query-core'
|
|
6
5
|
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'
|
|
7
6
|
import { useQueryClient } from './QueryClientProvider'
|
|
8
|
-
import type { UseBaseQueryOptions } from './types'
|
|
9
7
|
import { useIsRestoring } from './isRestoring'
|
|
10
8
|
import {
|
|
11
9
|
ensurePreventErrorBoundaryRetry,
|
|
12
10
|
getHasError,
|
|
13
11
|
useClearResetErrorBoundary,
|
|
14
12
|
} from './errorBoundaryUtils'
|
|
15
|
-
import { ensureStaleTime,
|
|
13
|
+
import { ensureStaleTime, fetchOptimistic, shouldSuspend } from './suspense'
|
|
14
|
+
import type { UseBaseQueryOptions } from './types'
|
|
15
|
+
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'
|
|
16
16
|
|
|
17
17
|
export function useBaseQuery<
|
|
18
18
|
TQueryFnData,
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
3
|
+
import { useBaseQuery } from './useBaseQuery'
|
|
2
4
|
import type {
|
|
3
|
-
QueryObserver,
|
|
4
|
-
QueryKey,
|
|
5
|
-
QueryClient,
|
|
6
5
|
DefaultError,
|
|
7
6
|
InfiniteData,
|
|
7
|
+
QueryClient,
|
|
8
|
+
QueryKey,
|
|
9
|
+
QueryObserver,
|
|
8
10
|
} from '@tanstack/query-core'
|
|
9
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
10
11
|
import type { UseInfiniteQueryOptions, UseInfiniteQueryResult } from './types'
|
|
11
|
-
import { useBaseQuery } from './useBaseQuery'
|
|
12
12
|
|
|
13
13
|
// HOOK
|
|
14
14
|
export function useInfiniteQuery<
|
package/src/useIsFetching.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
|
-
import type { QueryClient, QueryFilters } from '@tanstack/query-core'
|
|
4
3
|
import { notifyManager } from '@tanstack/query-core'
|
|
5
4
|
|
|
6
5
|
import { useQueryClient } from './QueryClientProvider'
|
|
6
|
+
import type { QueryClient, QueryFilters } from '@tanstack/query-core'
|
|
7
7
|
|
|
8
8
|
export function useIsFetching(
|
|
9
9
|
filters?: QueryFilters,
|
package/src/useMutation.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
|
-
import
|
|
4
|
-
import { notifyManager, MutationObserver } from '@tanstack/query-core'
|
|
3
|
+
import { MutationObserver, notifyManager } from '@tanstack/query-core'
|
|
5
4
|
import { useQueryClient } from './QueryClientProvider'
|
|
5
|
+
import { shouldThrowError } from './utils'
|
|
6
6
|
import type {
|
|
7
7
|
UseMutateFunction,
|
|
8
8
|
UseMutationOptions,
|
|
9
9
|
UseMutationResult,
|
|
10
10
|
} from './types'
|
|
11
|
-
import {
|
|
11
|
+
import type { DefaultError, QueryClient } from '@tanstack/query-core'
|
|
12
12
|
|
|
13
13
|
// HOOK
|
|
14
14
|
|
package/src/useMutationState.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
+
import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
|
|
5
|
+
import { useQueryClient } from './QueryClientProvider'
|
|
4
6
|
import type {
|
|
5
|
-
|
|
6
|
-
QueryClient,
|
|
7
|
+
DefaultError,
|
|
7
8
|
Mutation,
|
|
8
9
|
MutationCache,
|
|
9
|
-
|
|
10
|
+
MutationFilters,
|
|
10
11
|
MutationState,
|
|
12
|
+
QueryClient,
|
|
11
13
|
} from '@tanstack/query-core'
|
|
12
|
-
import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
|
|
13
|
-
import { useQueryClient } from './QueryClientProvider'
|
|
14
14
|
|
|
15
15
|
export function useIsMutating(
|
|
16
16
|
filters?: MutationFilters,
|
package/src/useQueries.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
QueryKey,
|
|
6
|
-
QueryFunction,
|
|
7
|
-
QueriesPlaceholderDataFunction,
|
|
8
|
-
QueryClient,
|
|
9
|
-
DefaultError,
|
|
10
|
-
QueriesObserverOptions,
|
|
11
|
-
} from '@tanstack/query-core'
|
|
12
|
-
import { notifyManager, QueriesObserver } from '@tanstack/query-core'
|
|
4
|
+
import { QueriesObserver, notifyManager } from '@tanstack/query-core'
|
|
13
5
|
import { useQueryClient } from './QueryClientProvider'
|
|
14
|
-
import type { UseQueryOptions, UseQueryResult } from './types'
|
|
15
6
|
import { useIsRestoring } from './isRestoring'
|
|
16
7
|
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'
|
|
17
8
|
import {
|
|
@@ -21,10 +12,19 @@ import {
|
|
|
21
12
|
} from './errorBoundaryUtils'
|
|
22
13
|
import {
|
|
23
14
|
ensureStaleTime,
|
|
24
|
-
shouldSuspend,
|
|
25
15
|
fetchOptimistic,
|
|
16
|
+
shouldSuspend,
|
|
26
17
|
willFetch,
|
|
27
18
|
} from './suspense'
|
|
19
|
+
import type { UseQueryOptions, UseQueryResult } from './types'
|
|
20
|
+
import type {
|
|
21
|
+
DefaultError,
|
|
22
|
+
QueriesObserverOptions,
|
|
23
|
+
QueriesPlaceholderDataFunction,
|
|
24
|
+
QueryClient,
|
|
25
|
+
QueryFunction,
|
|
26
|
+
QueryKey,
|
|
27
|
+
} from '@tanstack/query-core'
|
|
28
28
|
|
|
29
29
|
// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
|
|
30
30
|
// `placeholderData` function does not have a parameter
|
package/src/useQuery.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import type { QueryClient, QueryKey, DefaultError } from '@tanstack/query-core'
|
|
3
2
|
import { QueryObserver } from '@tanstack/query-core'
|
|
3
|
+
import { useBaseQuery } from './useBaseQuery'
|
|
4
|
+
import type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'
|
|
4
5
|
import type {
|
|
5
6
|
DefinedUseQueryResult,
|
|
6
7
|
UseQueryOptions,
|
|
7
8
|
UseQueryResult,
|
|
8
9
|
} from './types'
|
|
9
|
-
import { useBaseQuery } from './useBaseQuery'
|
|
10
10
|
import type {
|
|
11
11
|
DefinedInitialDataOptions,
|
|
12
12
|
UndefinedInitialDataOptions,
|