@tanstack/react-query 4.22.3 → 4.22.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "4.22.
|
|
3
|
+
"version": "4.22.4",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"use-sync-external-store": "^1.2.0",
|
|
50
|
-
"@tanstack/query-core": "4.22.
|
|
50
|
+
"@tanstack/query-core": "4.22.4"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
@@ -1044,7 +1044,7 @@ describe('useMutation', () => {
|
|
|
1044
1044
|
)
|
|
1045
1045
|
})
|
|
1046
1046
|
|
|
1047
|
-
|
|
1047
|
+
it('should go to error state if onSuccess callback errors', async () => {
|
|
1048
1048
|
const error = new Error('error from onSuccess')
|
|
1049
1049
|
const onError = jest.fn()
|
|
1050
1050
|
|
|
@@ -1079,7 +1079,7 @@ describe('useMutation', () => {
|
|
|
1079
1079
|
expect(onError).toHaveBeenCalledWith(error, 'todo', undefined)
|
|
1080
1080
|
})
|
|
1081
1081
|
|
|
1082
|
-
|
|
1082
|
+
it('should go to error state if onError callback errors', async () => {
|
|
1083
1083
|
const error = new Error('error from onError')
|
|
1084
1084
|
const mutateFnError = new Error('mutateFnError')
|
|
1085
1085
|
|
|
@@ -1115,7 +1115,7 @@ describe('useMutation', () => {
|
|
|
1115
1115
|
await rendered.findByText('error: mutateFnError, status: error')
|
|
1116
1116
|
})
|
|
1117
1117
|
|
|
1118
|
-
|
|
1118
|
+
it('should go to error state if onSettled callback errors', async () => {
|
|
1119
1119
|
const error = new Error('error from onSettled')
|
|
1120
1120
|
const mutateFnError = new Error('mutateFnError')
|
|
1121
1121
|
const onError = jest.fn()
|
|
@@ -1154,4 +1154,60 @@ describe('useMutation', () => {
|
|
|
1154
1154
|
|
|
1155
1155
|
expect(onError).toHaveBeenCalledWith(mutateFnError, 'todo', undefined)
|
|
1156
1156
|
})
|
|
1157
|
+
|
|
1158
|
+
it('should not call mutate callbacks for mutations started after unmount', async () => {
|
|
1159
|
+
const onSuccessMutate = jest.fn()
|
|
1160
|
+
const onSuccessUseMutation = jest.fn()
|
|
1161
|
+
const onSettledMutate = jest.fn()
|
|
1162
|
+
const onSettledUseMutation = jest.fn()
|
|
1163
|
+
|
|
1164
|
+
function Page() {
|
|
1165
|
+
const [show, setShow] = React.useState(true)
|
|
1166
|
+
return (
|
|
1167
|
+
<div>
|
|
1168
|
+
<button onClick={() => setShow(false)}>hide</button>
|
|
1169
|
+
{show && <Component />}
|
|
1170
|
+
</div>
|
|
1171
|
+
)
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
function Component() {
|
|
1175
|
+
const mutation = useMutation({
|
|
1176
|
+
mutationFn: async (text: string) => {
|
|
1177
|
+
await sleep(10)
|
|
1178
|
+
return text
|
|
1179
|
+
},
|
|
1180
|
+
onSuccess: onSuccessUseMutation,
|
|
1181
|
+
onSettled: onSettledUseMutation,
|
|
1182
|
+
})
|
|
1183
|
+
|
|
1184
|
+
return (
|
|
1185
|
+
<div>
|
|
1186
|
+
<button
|
|
1187
|
+
onClick={() => {
|
|
1188
|
+
setActTimeout(() => {
|
|
1189
|
+
mutation.mutate('todo', {
|
|
1190
|
+
onSuccess: onSuccessMutate,
|
|
1191
|
+
onSettled: onSettledMutate,
|
|
1192
|
+
})
|
|
1193
|
+
}, 10)
|
|
1194
|
+
}}
|
|
1195
|
+
>
|
|
1196
|
+
mutate
|
|
1197
|
+
</button>
|
|
1198
|
+
</div>
|
|
1199
|
+
)
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
const rendered = renderWithClient(queryClient, <Page />)
|
|
1203
|
+
|
|
1204
|
+
fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
|
|
1205
|
+
fireEvent.click(rendered.getByRole('button', { name: /hide/i }))
|
|
1206
|
+
|
|
1207
|
+
await waitFor(() => expect(onSuccessUseMutation).toHaveBeenCalledTimes(1))
|
|
1208
|
+
await waitFor(() => expect(onSettledUseMutation).toHaveBeenCalledTimes(1))
|
|
1209
|
+
|
|
1210
|
+
expect(onSuccessMutate).toHaveBeenCalledTimes(0)
|
|
1211
|
+
expect(onSettledMutate).toHaveBeenCalledTimes(0)
|
|
1212
|
+
})
|
|
1157
1213
|
})
|