@tanstack/react-query 5.8.2 → 5.8.3
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": "5.8.
|
|
3
|
+
"version": "5.8.3",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"!build/codemods/**/__tests__"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@tanstack/query-core": "5.8.
|
|
44
|
+
"@tanstack/query-core": "5.8.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/react": "^18.2.31",
|
|
@@ -6226,6 +6226,101 @@ describe('useQuery', () => {
|
|
|
6226
6226
|
await waitFor(() => rendered.getByText('Works'))
|
|
6227
6227
|
})
|
|
6228
6228
|
|
|
6229
|
+
it('should keep the previous data when placeholderData is set and cache is used', async () => {
|
|
6230
|
+
const key = queryKey()
|
|
6231
|
+
const states: Array<UseQueryResult<number | undefined>> = []
|
|
6232
|
+
const steps = [0, 1, 0, 2]
|
|
6233
|
+
|
|
6234
|
+
function Page() {
|
|
6235
|
+
const [count, setCount] = React.useState(0)
|
|
6236
|
+
|
|
6237
|
+
const state = useQuery({
|
|
6238
|
+
staleTime: Infinity,
|
|
6239
|
+
queryKey: [key, steps[count]],
|
|
6240
|
+
queryFn: async () => {
|
|
6241
|
+
await sleep(10)
|
|
6242
|
+
return steps[count]
|
|
6243
|
+
},
|
|
6244
|
+
placeholderData: keepPreviousData,
|
|
6245
|
+
})
|
|
6246
|
+
|
|
6247
|
+
states.push(state)
|
|
6248
|
+
|
|
6249
|
+
return (
|
|
6250
|
+
<div>
|
|
6251
|
+
<div>data: {state.data}</div>
|
|
6252
|
+
<button onClick={() => setCount((c) => c + 1)}>setCount</button>
|
|
6253
|
+
</div>
|
|
6254
|
+
)
|
|
6255
|
+
}
|
|
6256
|
+
|
|
6257
|
+
const rendered = renderWithClient(queryClient, <Page />)
|
|
6258
|
+
|
|
6259
|
+
await waitFor(() => rendered.getByText('data: 0'))
|
|
6260
|
+
|
|
6261
|
+
fireEvent.click(rendered.getByRole('button', { name: 'setCount' }))
|
|
6262
|
+
|
|
6263
|
+
await waitFor(() => rendered.getByText('data: 1'))
|
|
6264
|
+
|
|
6265
|
+
fireEvent.click(rendered.getByRole('button', { name: 'setCount' }))
|
|
6266
|
+
|
|
6267
|
+
await waitFor(() => rendered.getByText('data: 0'))
|
|
6268
|
+
|
|
6269
|
+
fireEvent.click(rendered.getByRole('button', { name: 'setCount' }))
|
|
6270
|
+
|
|
6271
|
+
await waitFor(() => rendered.getByText('data: 2'))
|
|
6272
|
+
|
|
6273
|
+
// Initial
|
|
6274
|
+
expect(states[0]).toMatchObject({
|
|
6275
|
+
data: undefined,
|
|
6276
|
+
isFetching: true,
|
|
6277
|
+
isSuccess: false,
|
|
6278
|
+
isPlaceholderData: false,
|
|
6279
|
+
})
|
|
6280
|
+
// Fetched
|
|
6281
|
+
expect(states[1]).toMatchObject({
|
|
6282
|
+
data: 0,
|
|
6283
|
+
isFetching: false,
|
|
6284
|
+
isSuccess: true,
|
|
6285
|
+
isPlaceholderData: false,
|
|
6286
|
+
})
|
|
6287
|
+
// Set state
|
|
6288
|
+
expect(states[2]).toMatchObject({
|
|
6289
|
+
data: 0,
|
|
6290
|
+
isFetching: true,
|
|
6291
|
+
isSuccess: true,
|
|
6292
|
+
isPlaceholderData: true,
|
|
6293
|
+
})
|
|
6294
|
+
// New data
|
|
6295
|
+
expect(states[3]).toMatchObject({
|
|
6296
|
+
data: 1,
|
|
6297
|
+
isFetching: false,
|
|
6298
|
+
isSuccess: true,
|
|
6299
|
+
isPlaceholderData: false,
|
|
6300
|
+
})
|
|
6301
|
+
// Set state with existing data
|
|
6302
|
+
expect(states[4]).toMatchObject({
|
|
6303
|
+
data: 0,
|
|
6304
|
+
isFetching: false,
|
|
6305
|
+
isSuccess: true,
|
|
6306
|
+
isPlaceholderData: false,
|
|
6307
|
+
})
|
|
6308
|
+
// Set state where the placeholder value should come from cache request
|
|
6309
|
+
expect(states[5]).toMatchObject({
|
|
6310
|
+
data: 0,
|
|
6311
|
+
isFetching: true,
|
|
6312
|
+
isSuccess: true,
|
|
6313
|
+
isPlaceholderData: true,
|
|
6314
|
+
})
|
|
6315
|
+
// New data
|
|
6316
|
+
expect(states[6]).toMatchObject({
|
|
6317
|
+
data: 2,
|
|
6318
|
+
isFetching: false,
|
|
6319
|
+
isSuccess: true,
|
|
6320
|
+
isPlaceholderData: false,
|
|
6321
|
+
})
|
|
6322
|
+
})
|
|
6323
|
+
|
|
6229
6324
|
// For Project without TS, when migrating from v4 to v5, make sure invalid calls due to bad parameters are tracked.
|
|
6230
6325
|
it('should throw in case of bad arguments to enhance DevX', async () => {
|
|
6231
6326
|
// Mock console error to avoid noise when test is run
|