Skip to content

Commit 0cbf7c8

Browse files
committed
Merge branch 'master' into feature/2181-useQueries-keepPreviousData
2 parents 2ff8feb + ff830db commit 0cbf7c8

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

docs/src/pages/guides/infinite-queries.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ queryClient.setQueryData('projects', data => ({
158158
Manually removing a single value from an individual page:
159159

160160
```js
161-
const newPagesArray = []
162-
oldPagesArray?.pages.forEach(page => {
163-
const newData = page.filter(val => val.id !== updatedId)
164-
newPagesArray.push(newData)
165-
})
161+
const newPagesArray = oldPagesArray?.pages.map((page) =>
162+
page.filter((val) => val.id !== updatedId)
163+
) ?? []
164+
166165
queryClient.setQueryData('projects', data => ({
167166
pages: newPagesArray,
168167
pageParams: data.pageParams,

src/core/tests/queryClient.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe('queryClient', () => {
344344
const data = {
345345
pages: ['data'],
346346
pageParams: [undefined],
347-
}
347+
} as const
348348

349349
const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () =>
350350
Promise.resolve(data.pages[0])

src/core/tests/utils.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ describe('core/utils', () => {
295295
expect(result.todos).not.toBe(next.todos)
296296
expect(result.todos[0]).not.toBe(prev.todos[0])
297297
expect(result.todos[0]).not.toBe(next.todos[0])
298-
expect(result.todos[0].id).toBe(next.todos[0].id)
299-
expect(result.todos[0].meta).toBe(prev.todos[0].meta)
300-
expect(result.todos[0].state).not.toBe(next.todos[0].state)
301-
expect(result.todos[0].state.done).toBe(next.todos[0].state.done)
298+
expect(result.todos[0]?.id).toBe(next.todos[0]?.id)
299+
expect(result.todos[0]?.meta).toBe(prev.todos[0]?.meta)
300+
expect(result.todos[0]?.state).not.toBe(next.todos[0]?.state)
301+
expect(result.todos[0]?.state.done).toBe(next.todos[0]?.state.done)
302302
expect(result.todos[1]).toBe(prev.todos[1])
303303
})
304304
})

src/devtools/devtools.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ThemeProvider, defaultTheme as theme } from './theme'
2121
import { getQueryStatusLabel, getQueryStatusColor } from './utils'
2222
import Explorer from './Explorer'
2323
import Logo from './Logo'
24+
import { noop } from '../core/utils'
2425

2526
interface DevtoolsOptions {
2627
/**
@@ -384,6 +385,11 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
384385
return undefined
385386
}, [isOpen, sort, sortFn, sortDesc, setUnsortedQueries, queryCache])
386387

388+
const handleRefetch = () => {
389+
const promise = activeQuery.fetch()
390+
promise.catch(noop)
391+
}
392+
387393
return (
388394
<ThemeProvider theme={theme}>
389395
<Panel
@@ -710,7 +716,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
710716
>
711717
<Button
712718
type="button"
713-
onClick={() => activeQuery.fetch()}
719+
onClick={handleRefetch}
714720
disabled={activeQuery.state.isFetching}
715721
style={{
716722
background: theme.active,

src/react/tests/useQuery.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ describe('useQuery', () => {
818818
expect(states[0]).toMatchObject({ data: undefined, isFetching: true })
819819
expect(states[1]).toMatchObject({ data: 'test', isFetching: false })
820820
expect(states[2]).toMatchObject({ data: 'test', isFetching: false })
821-
expect(states[1].dataUpdatedAt).not.toBe(states[2].dataUpdatedAt)
821+
expect(states[1]?.dataUpdatedAt).not.toBe(states[2]?.dataUpdatedAt)
822822
})
823823

824824
it('should track properties and only re-render when a tracked property changes', async () => {
@@ -1039,13 +1039,13 @@ describe('useQuery', () => {
10391039

10401040
await waitFor(() => expect(states.length).toBe(4))
10411041

1042-
const todos = states[2].data!
1043-
const todo1 = todos[0]
1044-
const todo2 = todos[1]
1042+
const todos = states[2]?.data
1043+
const todo1 = todos?.[0]
1044+
const todo2 = todos?.[1]
10451045

1046-
const newTodos = states[3].data!
1047-
const newTodo1 = newTodos[0]
1048-
const newTodo2 = newTodos[1]
1046+
const newTodos = states[3]?.data
1047+
const newTodo1 = newTodos?.[0]
1048+
const newTodo2 = newTodos?.[1]
10491049

10501050
expect(todos).toEqual(result1)
10511051
expect(newTodos).toEqual(result2)
@@ -1465,7 +1465,7 @@ describe('useQuery', () => {
14651465
status: 'error',
14661466
isPreviousData: false,
14671467
})
1468-
expect(states[7].error).toHaveProperty('message', 'Error test')
1468+
expect(states[7]?.error).toHaveProperty('message', 'Error test')
14691469

14701470
consoleMock.mockRestore()
14711471
})
@@ -2304,7 +2304,7 @@ describe('useQuery', () => {
23042304

23052305
await sleep(20)
23062306

2307-
expect(states[1].data).toEqual([key, variables])
2307+
expect(states[1]?.data).toEqual([key, variables])
23082308
})
23092309

23102310
it('should not refetch query on focus when `enabled` is set to `false`', async () => {

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"noImplicitThis": true,
1212
"noUnusedLocals": true,
1313
"noUnusedParameters": true,
14+
"noUncheckedIndexedAccess": true,
1415
"skipLibCheck": true,
1516
"strict": true,
1617
"types": ["jest"],

0 commit comments

Comments
 (0)