@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.
Files changed (87) hide show
  1. package/build/lib/HydrationBoundary.cjs.map +1 -1
  2. package/build/lib/HydrationBoundary.d.ts.map +1 -1
  3. package/build/lib/HydrationBoundary.js.map +1 -1
  4. package/build/lib/HydrationBoundary.legacy.cjs.map +1 -1
  5. package/build/lib/HydrationBoundary.legacy.js.map +1 -1
  6. package/build/lib/__tests__/utils.d.ts +4 -3
  7. package/build/lib/__tests__/utils.d.ts.map +1 -1
  8. package/build/lib/errorBoundaryUtils.cjs.map +1 -1
  9. package/build/lib/errorBoundaryUtils.d.ts.map +1 -1
  10. package/build/lib/errorBoundaryUtils.js.map +1 -1
  11. package/build/lib/errorBoundaryUtils.legacy.cjs.map +1 -1
  12. package/build/lib/errorBoundaryUtils.legacy.js.map +1 -1
  13. package/build/lib/suspense.cjs.map +1 -1
  14. package/build/lib/suspense.d.ts +1 -1
  15. package/build/lib/suspense.d.ts.map +1 -1
  16. package/build/lib/suspense.js.map +1 -1
  17. package/build/lib/suspense.legacy.cjs.map +1 -1
  18. package/build/lib/suspense.legacy.js.map +1 -1
  19. package/build/lib/types.d.ts +1 -1
  20. package/build/lib/types.d.ts.map +1 -1
  21. package/build/lib/useBaseQuery.cjs.map +1 -1
  22. package/build/lib/useBaseQuery.d.ts +1 -1
  23. package/build/lib/useBaseQuery.d.ts.map +1 -1
  24. package/build/lib/useBaseQuery.js.map +1 -1
  25. package/build/lib/useBaseQuery.legacy.cjs.map +1 -1
  26. package/build/lib/useBaseQuery.legacy.js.map +1 -1
  27. package/build/lib/useInfiniteQuery.cjs.map +1 -1
  28. package/build/lib/useInfiniteQuery.d.ts +1 -1
  29. package/build/lib/useInfiniteQuery.d.ts.map +1 -1
  30. package/build/lib/useInfiniteQuery.js.map +1 -1
  31. package/build/lib/useInfiniteQuery.legacy.cjs.map +1 -1
  32. package/build/lib/useInfiniteQuery.legacy.js.map +1 -1
  33. package/build/lib/useIsFetching.cjs.map +1 -1
  34. package/build/lib/useIsFetching.d.ts.map +1 -1
  35. package/build/lib/useIsFetching.js.map +1 -1
  36. package/build/lib/useIsFetching.legacy.cjs.map +1 -1
  37. package/build/lib/useIsFetching.legacy.js.map +1 -1
  38. package/build/lib/useMutation.cjs.map +1 -1
  39. package/build/lib/useMutation.d.ts +1 -1
  40. package/build/lib/useMutation.d.ts.map +1 -1
  41. package/build/lib/useMutation.js.map +1 -1
  42. package/build/lib/useMutation.legacy.cjs.map +1 -1
  43. package/build/lib/useMutation.legacy.js.map +1 -1
  44. package/build/lib/useMutationState.cjs.map +1 -1
  45. package/build/lib/useMutationState.d.ts +1 -1
  46. package/build/lib/useMutationState.d.ts.map +1 -1
  47. package/build/lib/useMutationState.js.map +1 -1
  48. package/build/lib/useMutationState.legacy.cjs.map +1 -1
  49. package/build/lib/useMutationState.legacy.js.map +1 -1
  50. package/build/lib/useQueries.cjs.map +1 -1
  51. package/build/lib/useQueries.d.ts +1 -1
  52. package/build/lib/useQueries.d.ts.map +1 -1
  53. package/build/lib/useQueries.js.map +1 -1
  54. package/build/lib/useQueries.legacy.cjs.map +1 -1
  55. package/build/lib/useQueries.legacy.js.map +1 -1
  56. package/build/lib/useQuery.cjs.map +1 -1
  57. package/build/lib/useQuery.d.ts +1 -1
  58. package/build/lib/useQuery.d.ts.map +1 -1
  59. package/build/lib/useQuery.js.map +1 -1
  60. package/build/lib/useQuery.legacy.cjs.map +1 -1
  61. package/build/lib/useQuery.legacy.js.map +1 -1
  62. package/package.json +2 -2
  63. package/src/HydrationBoundary.tsx +1 -1
  64. package/src/__tests__/HydrationBoundary.test.tsx +5 -5
  65. package/src/__tests__/QueryClientProvider.test.tsx +2 -2
  66. package/src/__tests__/QueryResetErrorBoundary.test.tsx +2 -2
  67. package/src/__tests__/ssr-hydration.test.tsx +2 -2
  68. package/src/__tests__/ssr.test.tsx +2 -2
  69. package/src/__tests__/suspense.test.tsx +2 -2
  70. package/src/__tests__/useInfiniteQuery.test.tsx +2 -2
  71. package/src/__tests__/useInfiniteQuery.type.test.tsx +2 -2
  72. package/src/__tests__/useIsFetching.test.tsx +1 -1
  73. package/src/__tests__/useMutation.test.tsx +2 -2
  74. package/src/__tests__/useQueries.test.tsx +8 -8
  75. package/src/__tests__/useQuery.test.tsx +14 -13
  76. package/src/__tests__/useQuery.types.test.tsx +1 -1
  77. package/src/__tests__/utils.tsx +7 -4
  78. package/src/errorBoundaryUtils.ts +2 -2
  79. package/src/suspense.ts +1 -1
  80. package/src/types.ts +5 -5
  81. package/src/useBaseQuery.ts +3 -3
  82. package/src/useInfiniteQuery.ts +5 -5
  83. package/src/useIsFetching.ts +1 -1
  84. package/src/useMutation.ts +3 -3
  85. package/src/useMutationState.ts +5 -5
  86. package/src/useQueries.ts +11 -11
  87. 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 null
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 sleep(20)
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 sleep(20)
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', () => {
@@ -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(value: DocumentVisibilityState) {
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
@@ -1,8 +1,8 @@
1
1
  import type {
2
2
  DefaultedQueryObserverOptions,
3
- QueryObserverResult,
4
3
  QueryKey,
5
4
  QueryObserver,
5
+ QueryObserverResult,
6
6
  } from '@tanstack/query-core'
7
7
  import type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'
8
8
 
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<
@@ -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, shouldSuspend, fetchOptimistic } from './suspense'
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,
@@ -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<
@@ -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,
@@ -1,14 +1,14 @@
1
1
  'use client'
2
2
  import * as React from 'react'
3
- import type { QueryClient, DefaultError } from '@tanstack/query-core'
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 { shouldThrowError } from './utils'
11
+ import type { DefaultError, QueryClient } from '@tanstack/query-core'
12
12
 
13
13
  // HOOK
14
14
 
@@ -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
- MutationFilters,
6
- QueryClient,
7
+ DefaultError,
7
8
  Mutation,
8
9
  MutationCache,
9
- DefaultError,
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 type {
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,