@tanstack/react-query 4.3.3 → 4.3.6

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 (34) hide show
  1. package/build/lib/__tests__/Hydrate.test.d.ts +1 -0
  2. package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
  3. package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +6 -0
  4. package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
  5. package/build/lib/__tests__/ssr.test.d.ts +4 -0
  6. package/build/lib/__tests__/suspense.test.d.ts +1 -0
  7. package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
  8. package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
  9. package/build/lib/__tests__/useIsMutating.test.d.ts +1 -0
  10. package/build/lib/__tests__/useMutation.test.d.ts +1 -0
  11. package/build/lib/__tests__/useQueries.test.d.ts +1 -0
  12. package/build/lib/__tests__/useQuery.test.d.ts +1 -0
  13. package/build/lib/__tests__/useQuery.types.test.d.ts +2 -0
  14. package/build/lib/__tests__/utils.d.ts +31 -0
  15. package/build/lib/setBatchUpdatesFn.js +1 -1
  16. package/build/lib/setBatchUpdatesFn.js.map +1 -1
  17. package/build/umd/index.development.js +1 -0
  18. package/build/umd/index.development.js.map +1 -1
  19. package/build/umd/index.production.js +1 -1
  20. package/build/umd/index.production.js.map +1 -1
  21. package/package.json +2 -2
  22. package/src/__tests__/Hydrate.test.tsx +1 -1
  23. package/src/__tests__/QueryClientProvider.test.tsx +1 -1
  24. package/src/__tests__/QueryResetErrorBoundary.test.tsx +3 -4
  25. package/src/__tests__/ssr-hydration.test.tsx +1 -6
  26. package/src/__tests__/ssr.test.tsx +1 -1
  27. package/src/__tests__/suspense.test.tsx +5 -6
  28. package/src/__tests__/useInfiniteQuery.test.tsx +9 -9
  29. package/src/__tests__/useIsFetching.test.tsx +3 -3
  30. package/src/__tests__/useIsMutating.test.tsx +3 -4
  31. package/src/__tests__/useMutation.test.tsx +3 -3
  32. package/src/__tests__/useQueries.test.tsx +8 -8
  33. package/src/__tests__/useQuery.test.tsx +12 -11
  34. package/src/__tests__/utils.tsx +82 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query",
3
- "version": "4.3.3",
3
+ "version": "4.3.6",
4
4
  "description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -46,7 +46,7 @@
46
46
  "react-error-boundary": "^3.1.4"
47
47
  },
48
48
  "dependencies": {
49
- "@tanstack/query-core": "4.3.3",
49
+ "@tanstack/query-core": "4.3.6",
50
50
  "use-sync-external-store": "^1.2.0"
51
51
  },
52
52
  "peerDependencies": {
@@ -10,7 +10,7 @@ import {
10
10
  useHydrate,
11
11
  Hydrate,
12
12
  } from '@tanstack/react-query'
13
- import { createQueryClient, sleep } from '../../../../tests/utils'
13
+ import { createQueryClient, sleep } from './utils'
14
14
  import * as coreModule from '@tanstack/query-core'
15
15
 
16
16
  describe('React hydration', () => {
@@ -2,7 +2,7 @@ import * as React from 'react'
2
2
  import { render, waitFor } from '@testing-library/react'
3
3
  import { renderToString } from 'react-dom/server'
4
4
 
5
- import { sleep, queryKey, createQueryClient } from '../../../../tests/utils'
5
+ import { sleep, queryKey, createQueryClient } from './utils'
6
6
  import {
7
7
  QueryClient,
8
8
  QueryClientProvider,
@@ -1,10 +1,9 @@
1
- import { waitFor, fireEvent } from '@testing-library/react'
1
+ import { fireEvent, waitFor } from '@testing-library/react'
2
2
  import { ErrorBoundary } from 'react-error-boundary'
3
3
  import * as React from 'react'
4
4
 
5
- import { sleep, queryKey, createQueryClient } from '../../../../tests/utils'
6
- import { renderWithClient } from './utils'
7
- import { useQuery, QueryCache, QueryErrorResetBoundary } from '..'
5
+ import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
6
+ import { QueryCache, QueryErrorResetBoundary, useQuery } from '..'
8
7
 
9
8
  // TODO: This should be removed with the types for react-error-boundary get updated.
10
9
  declare module 'react-error-boundary' {
@@ -12,12 +12,7 @@ import {
12
12
  dehydrate,
13
13
  hydrate,
14
14
  } from '..'
15
- import {
16
- createQueryClient,
17
- mockLogger,
18
- setIsServer,
19
- sleep,
20
- } from '../../../../tests/utils'
15
+ import { createQueryClient, mockLogger, setIsServer, sleep } from './utils'
21
16
 
22
17
  const isReact18 = () => (process.env.REACTJS_VERSION || '18') === '18'
23
18
 
@@ -6,7 +6,7 @@ import * as React from 'react'
6
6
  // @ts-ignore
7
7
  import { renderToString } from 'react-dom/server'
8
8
 
9
- import { sleep, queryKey, createQueryClient } from '../../../../tests/utils'
9
+ import { sleep, queryKey, createQueryClient } from './utils'
10
10
  import { useQuery, QueryClientProvider, QueryCache, useInfiniteQuery } from '..'
11
11
 
12
12
  describe('Server Side Rendering', () => {
@@ -1,17 +1,16 @@
1
- import { waitFor, fireEvent } from '@testing-library/react'
1
+ import { fireEvent, waitFor } from '@testing-library/react'
2
2
  import { ErrorBoundary } from 'react-error-boundary'
3
3
  import * as React from 'react'
4
4
 
5
- import { sleep, queryKey, createQueryClient } from '../../../../tests/utils'
6
- import { renderWithClient } from './utils'
5
+ import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
7
6
  import {
8
- useQuery,
9
7
  QueryCache,
10
8
  QueryErrorResetBoundary,
9
+ useInfiniteQuery,
10
+ UseInfiniteQueryResult,
11
+ useQuery,
11
12
  useQueryErrorResetBoundary,
12
13
  UseQueryResult,
13
- UseInfiniteQueryResult,
14
- useInfiniteQuery,
15
14
  } from '..'
16
15
 
17
16
  describe("useQuery's in Suspense mode", () => {
@@ -1,20 +1,20 @@
1
- import { waitFor, fireEvent } from '@testing-library/react'
1
+ import { fireEvent, waitFor } from '@testing-library/react'
2
2
  import * as React from 'react'
3
3
 
4
4
  import {
5
+ Blink,
6
+ createQueryClient,
5
7
  queryKey,
6
- sleep,
8
+ renderWithClient,
7
9
  setActTimeout,
8
- createQueryClient,
9
- } from '../../../../tests/utils'
10
-
11
- import { renderWithClient, Blink } from './utils'
10
+ sleep,
11
+ } from './utils'
12
12
  import {
13
- useInfiniteQuery,
14
- UseInfiniteQueryResult,
13
+ InfiniteData,
15
14
  QueryCache,
16
15
  QueryFunctionContext,
17
- InfiniteData,
16
+ useInfiniteQuery,
17
+ UseInfiniteQueryResult,
18
18
  } from '..'
19
19
 
20
20
  interface Result {
@@ -5,11 +5,11 @@ import { ErrorBoundary } from 'react-error-boundary'
5
5
  import {
6
6
  createQueryClient,
7
7
  queryKey,
8
+ renderWithClient,
8
9
  setActTimeout,
9
10
  sleep,
10
- } from '../../../../tests/utils'
11
- import { renderWithClient } from './utils'
12
- import { QueryClient, useQuery, useIsFetching, QueryCache } from '..'
11
+ } from './utils'
12
+ import { QueryCache, QueryClient, useIsFetching, useQuery } from '..'
13
13
 
14
14
  describe('useIsFetching', () => {
15
15
  // See https://github.com/tannerlinsley/react-query/issues/105
@@ -1,14 +1,13 @@
1
- import { waitFor, fireEvent } from '@testing-library/react'
1
+ import { fireEvent, waitFor } from '@testing-library/react'
2
2
  import * as React from 'react'
3
3
  import { useIsMutating } from '../useIsMutating'
4
4
  import { useMutation } from '../useMutation'
5
5
  import {
6
6
  createQueryClient,
7
+ renderWithClient,
7
8
  setActTimeout,
8
9
  sleep,
9
- } from '../../../../tests/utils'
10
-
11
- import { renderWithClient } from './utils'
10
+ } from './utils'
12
11
  import { ErrorBoundary } from 'react-error-boundary'
13
12
  import { QueryClient } from '@tanstack/query-core'
14
13
  import * as MutationCacheModule from '../../../query-core/src/mutationCache'
@@ -3,16 +3,16 @@ import '@testing-library/jest-dom'
3
3
  import * as React from 'react'
4
4
  import { ErrorBoundary } from 'react-error-boundary'
5
5
 
6
- import { QueryClient, useMutation, QueryCache, MutationCache } from '..'
6
+ import { MutationCache, QueryCache, QueryClient, useMutation } from '..'
7
7
  import { UseMutationResult } from '../types'
8
8
  import {
9
9
  createQueryClient,
10
10
  mockNavigatorOnLine,
11
11
  queryKey,
12
+ renderWithClient,
12
13
  setActTimeout,
13
14
  sleep,
14
- } from '../../../../tests/utils'
15
- import { renderWithClient } from './utils'
15
+ } from './utils'
16
16
 
17
17
  describe('useMutation', () => {
18
18
  const queryCache = new QueryCache()
@@ -9,19 +9,19 @@ import {
9
9
  expectType,
10
10
  expectTypeNotAny,
11
11
  queryKey,
12
+ renderWithClient,
12
13
  sleep,
13
- } from '../../../../tests/utils'
14
- import { renderWithClient } from './utils'
14
+ } from './utils'
15
15
  import {
16
- QueryClient,
17
- useQueries,
18
- UseQueryResult,
19
- QueryCache,
20
- QueryObserverResult,
21
16
  QueriesObserver,
17
+ QueryCache,
18
+ QueryClient,
22
19
  QueryFunction,
23
- UseQueryOptions,
24
20
  QueryKey,
21
+ QueryObserverResult,
22
+ useQueries,
23
+ UseQueryOptions,
24
+ UseQueryResult,
25
25
  } from '..'
26
26
  import { QueryFunctionContext } from '@tanstack/query-core'
27
27
 
@@ -1,25 +1,26 @@
1
- import { act, waitFor, fireEvent } from '@testing-library/react'
1
+ import { act, fireEvent, waitFor } from '@testing-library/react'
2
2
  import '@testing-library/jest-dom'
3
3
  import * as React from 'react'
4
4
  import {
5
+ Blink,
6
+ createQueryClient,
5
7
  expectType,
6
- queryKey,
8
+ mockLogger,
9
+ mockNavigatorOnLine,
7
10
  mockVisibilityState,
8
- sleep,
11
+ queryKey,
12
+ renderWithClient,
9
13
  setActTimeout,
10
- mockNavigatorOnLine,
11
- mockLogger,
12
- createQueryClient,
13
- } from '../../../../tests/utils'
14
- import { renderWithClient, Blink } from './utils'
14
+ sleep,
15
+ } from './utils'
15
16
  import {
16
- useQuery,
17
- UseQueryResult,
17
+ DefinedUseQueryResult,
18
18
  QueryCache,
19
19
  QueryFunction,
20
20
  QueryFunctionContext,
21
+ useQuery,
21
22
  UseQueryOptions,
22
- DefinedUseQueryResult,
23
+ UseQueryResult,
23
24
  } from '..'
24
25
  import { ErrorBoundary } from 'react-error-boundary'
25
26
 
@@ -1,7 +1,13 @@
1
1
  import * as React from 'react'
2
- import { render } from '@testing-library/react'
3
- import { setActTimeout } from '../../../../tests/utils'
4
- import { QueryClient, ContextOptions, QueryClientProvider } from '..'
2
+ import { act, render } from '@testing-library/react'
3
+ import {
4
+ QueryClient,
5
+ ContextOptions,
6
+ QueryClientProvider,
7
+ QueryClientConfig,
8
+ MutationOptions,
9
+ } from '..'
10
+ import * as utils from '@tanstack/query-core'
5
11
 
6
12
  export function renderWithClient(
7
13
  client: QueryClient,
@@ -43,3 +49,76 @@ export const Blink = ({
43
49
 
44
50
  return shouldShow ? <>{children}</> : <>off</>
45
51
  }
52
+
53
+ export function createQueryClient(config?: QueryClientConfig): QueryClient {
54
+ jest.spyOn(console, 'error').mockImplementation(() => undefined)
55
+ return new QueryClient({ logger: mockLogger, ...config })
56
+ }
57
+
58
+ export function mockVisibilityState(value: DocumentVisibilityState) {
59
+ return jest.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
60
+ }
61
+
62
+ export function mockNavigatorOnLine(value: boolean) {
63
+ return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
64
+ }
65
+
66
+ export const mockLogger = {
67
+ log: jest.fn(),
68
+ warn: jest.fn(),
69
+ error: jest.fn(),
70
+ }
71
+
72
+ let queryKeyCount = 0
73
+ export function queryKey(): Array<string> {
74
+ queryKeyCount++
75
+ return [`query_${queryKeyCount}`]
76
+ }
77
+
78
+ export function sleep(timeout: number): Promise<void> {
79
+ return new Promise((resolve, _reject) => {
80
+ setTimeout(resolve, timeout)
81
+ })
82
+ }
83
+
84
+ export function setActTimeout(fn: () => void, ms?: number) {
85
+ return setTimeout(() => {
86
+ act(() => {
87
+ fn()
88
+ })
89
+ }, ms)
90
+ }
91
+
92
+ /**
93
+ * Assert the parameter is of a specific type.
94
+ */
95
+ export function expectType<T>(_: T): void {
96
+ return undefined
97
+ }
98
+
99
+ /**
100
+ * Assert the parameter is not typed as `any`
101
+ */
102
+ export function expectTypeNotAny<T>(_: 0 extends 1 & T ? never : T): void {
103
+ return undefined
104
+ }
105
+
106
+ export function executeMutation(
107
+ queryClient: QueryClient,
108
+ options: MutationOptions<any, any, any, any>,
109
+ ): Promise<unknown> {
110
+ return queryClient.getMutationCache().build(queryClient, options).execute()
111
+ }
112
+
113
+ // This monkey-patches the isServer-value from utils,
114
+ // so that we can pretend to be in a server environment
115
+ export function setIsServer(isServer: boolean) {
116
+ const original = utils.isServer
117
+ // @ts-ignore
118
+ utils.isServer = isServer
119
+
120
+ return () => {
121
+ // @ts-ignore
122
+ utils.isServer = original
123
+ }
124
+ }