@tanstack/react-query 4.3.4 → 4.3.7
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/Hydrate.esm.js +31 -0
- package/build/lib/Hydrate.esm.js.map +1 -0
- package/build/lib/QueryClientProvider.esm.js +60 -0
- package/build/lib/QueryClientProvider.esm.js.map +1 -0
- package/build/lib/QueryErrorResetBoundary.esm.js +32 -0
- package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -0
- package/build/lib/__tests__/Hydrate.test.d.ts +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +6 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
- package/build/lib/__tests__/ssr.test.d.ts +4 -0
- package/build/lib/__tests__/suspense.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsMutating.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts +2 -0
- package/build/lib/__tests__/utils.d.ts +31 -0
- package/build/lib/index.esm.js +13 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/lib/isRestoring.esm.js +8 -0
- package/build/lib/isRestoring.esm.js.map +1 -0
- package/build/lib/reactBatchedUpdates.esm.js +6 -0
- package/build/lib/reactBatchedUpdates.esm.js.map +1 -0
- package/build/lib/reactBatchedUpdates.native.esm.js +2 -0
- package/build/lib/reactBatchedUpdates.native.esm.js.map +1 -0
- package/build/lib/setBatchUpdatesFn.esm.js +5 -0
- package/build/lib/setBatchUpdatesFn.esm.js.map +1 -0
- package/build/lib/useBaseQuery.esm.js +83 -0
- package/build/lib/useBaseQuery.esm.js.map +1 -0
- package/build/lib/useInfiniteQuery.esm.js +10 -0
- package/build/lib/useInfiniteQuery.esm.js.map +1 -0
- package/build/lib/useIsFetching.esm.js +16 -0
- package/build/lib/useIsFetching.esm.js.map +1 -0
- package/build/lib/useIsMutating.esm.js +16 -0
- package/build/lib/useIsMutating.esm.js.map +1 -0
- package/build/lib/useMutation.esm.js +34 -0
- package/build/lib/useMutation.esm.js.map +1 -0
- package/build/lib/useQueries.esm.js +37 -0
- package/build/lib/useQueries.esm.js.map +1 -0
- package/build/lib/useQuery.esm.js +10 -0
- package/build/lib/useQuery.esm.js.map +1 -0
- package/build/lib/utils.esm.js +11 -0
- package/build/lib/utils.esm.js.map +1 -0
- package/build/umd/index.development.js +1 -0
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -2
- package/src/__tests__/Hydrate.test.tsx +1 -1
- package/src/__tests__/QueryClientProvider.test.tsx +1 -1
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +3 -4
- package/src/__tests__/ssr-hydration.test.tsx +1 -6
- package/src/__tests__/ssr.test.tsx +1 -1
- package/src/__tests__/suspense.test.tsx +5 -6
- package/src/__tests__/useInfiniteQuery.test.tsx +9 -9
- package/src/__tests__/useIsFetching.test.tsx +3 -3
- package/src/__tests__/useIsMutating.test.tsx +3 -4
- package/src/__tests__/useMutation.test.tsx +3 -3
- package/src/__tests__/useQueries.test.tsx +8 -8
- package/src/__tests__/useQuery.test.tsx +12 -11
- 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
|
+
"version": "4.3.7",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"types": "build/lib/index.d.ts",
|
|
14
14
|
"main": "build/lib/index.js",
|
|
15
|
+
"module": "build/lib/index.esm.js",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
17
18
|
"types": "./build/lib/index.d.ts",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"react-error-boundary": "^3.1.4"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
|
-
"@tanstack/query-core": "4.3.
|
|
50
|
+
"@tanstack/query-core": "4.3.7",
|
|
50
51
|
"use-sync-external-store": "^1.2.0"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
useHydrate,
|
|
11
11
|
Hydrate,
|
|
12
12
|
} from '@tanstack/react-query'
|
|
13
|
-
import { createQueryClient, sleep } from '
|
|
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 '
|
|
5
|
+
import { sleep, queryKey, createQueryClient } from './utils'
|
|
6
6
|
import {
|
|
7
7
|
QueryClient,
|
|
8
8
|
QueryClientProvider,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
6
|
-
import {
|
|
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 '
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
8
|
+
renderWithClient,
|
|
7
9
|
setActTimeout,
|
|
8
|
-
|
|
9
|
-
} from '
|
|
10
|
-
|
|
11
|
-
import { renderWithClient, Blink } from './utils'
|
|
10
|
+
sleep,
|
|
11
|
+
} from './utils'
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
UseInfiniteQueryResult,
|
|
13
|
+
InfiniteData,
|
|
15
14
|
QueryCache,
|
|
16
15
|
QueryFunctionContext,
|
|
17
|
-
|
|
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 '
|
|
11
|
-
import {
|
|
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 {
|
|
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 '
|
|
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 {
|
|
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 '
|
|
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 '
|
|
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,
|
|
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
|
-
|
|
8
|
+
mockLogger,
|
|
9
|
+
mockNavigatorOnLine,
|
|
7
10
|
mockVisibilityState,
|
|
8
|
-
|
|
11
|
+
queryKey,
|
|
12
|
+
renderWithClient,
|
|
9
13
|
setActTimeout,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
createQueryClient,
|
|
13
|
-
} from '../../../../tests/utils'
|
|
14
|
-
import { renderWithClient, Blink } from './utils'
|
|
14
|
+
sleep,
|
|
15
|
+
} from './utils'
|
|
15
16
|
import {
|
|
16
|
-
|
|
17
|
-
UseQueryResult,
|
|
17
|
+
DefinedUseQueryResult,
|
|
18
18
|
QueryCache,
|
|
19
19
|
QueryFunction,
|
|
20
20
|
QueryFunctionContext,
|
|
21
|
+
useQuery,
|
|
21
22
|
UseQueryOptions,
|
|
22
|
-
|
|
23
|
+
UseQueryResult,
|
|
23
24
|
} from '..'
|
|
24
25
|
import { ErrorBoundary } from 'react-error-boundary'
|
|
25
26
|
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
-
import { render } from '@testing-library/react'
|
|
3
|
-
import {
|
|
4
|
-
|
|
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
|
+
}
|