Skip to content

Commit d0ea746

Browse files
committed
Merge branch 'main' into alpha
2 parents a968036 + bbdf720 commit d0ea746

File tree

10 files changed

+83
-46
lines changed

10 files changed

+83
-46
lines changed

docs/react/guides/infinite-queries.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ useInfiniteQuery({
142142

143143
## What if I want to manually update the infinite query?
144144

145-
Manually removing first page:
145+
### Manually removing first page:
146146

147147
[//]: # 'Example5'
148148

@@ -155,7 +155,7 @@ queryClient.setQueryData(['projects'], (data) => ({
155155

156156
[//]: # 'Example5'
157157

158-
Manually removing a single value from an individual page:
158+
### Manually removing a single value from an individual page:
159159

160160
[//]: # 'Example6'
161161

@@ -173,10 +173,24 @@ queryClient.setQueryData(['projects'], (data) => ({
173173

174174
[//]: # 'Example6'
175175

176-
Make sure to keep the same data structure of pages and pageParams!
176+
### Keep only the first page:
177177

178178
[//]: # 'Example7'
179179

180+
```tsx
181+
queryClient.setQueryData(['projects'], (data) => ({
182+
pages: data.pages.slice(0,1),
183+
pageParams: data.pageParams.slice(0,1),
184+
}))
185+
```
186+
187+
[//]: # 'Example7'
188+
189+
Make sure to always keep the same data structure of pages and pageParams!
190+
191+
192+
[//]: # 'Example8'
193+
180194
## What if I want to limit the number of pages?
181195

182196
In some use cases you may want to limit the number of pages stored in the query data to improve the performance and UX:
@@ -188,7 +202,7 @@ The solution is to use a "Limited Infinite Query". This is made possible by usin
188202

189203
In the following example only 3 pages are kept in the query data pages array. If a refetch is needed, only 3 pages will be refetched sequentially.
190204

191-
[//]: # 'Example7'
205+
[//]: # 'Example8'
192206

193207
```tsx
194208
useInfiniteQuery({
@@ -205,7 +219,7 @@ useInfiniteQuery({
205219

206220
If your API doesn't return a cursor, you can use the `pageParam` as a cursor. Because `getNextPageParam` and `getPreviousPageParam` also get the `pageParam`of the current page, you can use it to calculate the next / previous page param.
207221

208-
[//]: # 'Example8'
222+
[//]: # 'Example9'
209223

210224
```tsx
211225
return useInfiniteQuery({
@@ -227,4 +241,4 @@ return useInfiniteQuery({
227241
})
228242
```
229243

230-
[//]: # 'Example8'
244+
[//]: # 'Example9'

docs/react/reference/useMutation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mutate(variables, {
5353
- If set to `Infinity`, will disable garbage collection
5454
- `mutationKey: unknown[]`
5555
- Optional
56-
- A mutation key can be set to inherit defaults set with `queryClient.setMutationDefaults` or to identify the mutation in the devtools.
56+
- A mutation key can be set to inherit defaults set with `queryClient.setMutationDefaults`.
5757
- `networkMode: 'online' | 'always' | 'offlineFirst`
5858
- optional
5959
- defaults to `'online'`

docs/vue/devtools.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Wave your hands in the air and shout hooray because Vue Query comes with dedicat
77

88
When you begin your Vue Query journey, you'll want these devtools by your side. They help visualize all of the inner workings of Vue Query and will likely save you hours of debugging if you find yourself in a pinch!
99

10-
The only thing you need to do is to install official **[Vue Devtools](https://devtools.vuejs.org/guide/installation.html)**
10+
The only thing you need to do is to install the official **[Vue Devtools](https://devtools.vuejs.org/guide/installation.html)**.
1111

12-
Vue Query will seemingly integrate with official devtools, adding custom inspector and timeline events.
13-
Devtools would be treeshaken from production bundles by default.
12+
Vue Query will seamlessly integrate with the official devtools, adding custom inspector and timeline events.
13+
Devtool code will be treeshaken from production bundles by default.

docs/vue/guides/infinite-queries.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,3 @@ const {
5454
```
5555

5656
[//]: # 'Example'
57-
[//]: # 'Example6'
58-
59-
```tsx
60-
const newPagesArray =
61-
oldPagesArray?.pages.map((page) =>
62-
page.filter((val) => val.id !== updatedId),
63-
) ?? []
64-
65-
queryClient.setQueryData(['projects'], (data) => ({
66-
pages: newPagesArray,
67-
pageParams: data.pageParams,
68-
}))
69-
```
70-
71-
[//]: # 'Example6'

packages/query-core/src/focusManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ export class FocusManager extends Subscribable {
5656
}
5757

5858
setFocused(focused?: boolean): void {
59-
this.#focused = focused
60-
61-
if (focused) {
59+
const changed = this.#focused !== focused
60+
if (changed) {
61+
this.#focused = focused
6262
this.onFocus()
6363
}
6464
}

packages/query-core/src/onlineManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ export class OnlineManager extends Subscribable {
6363
}
6464

6565
setOnline(online?: boolean): void {
66-
this.#online = online
66+
const changed = this.#online !== online
6767

68-
if (online) {
68+
if (changed) {
69+
this.#online = online
6970
this.onOnline()
7071
}
7172
}

packages/query-core/src/tests/focusManager.test.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ describe('focusManager', () => {
3939
expect(focusManager.isFocused()).toBeTruthy()
4040
})
4141

42-
it('should not notify listeners on focus if already focused', async () => {
43-
const subscriptionSpy = vi.fn()
44-
const unsubscribe = focusManager.subscribe(subscriptionSpy)
45-
46-
focusManager.setFocused(true)
47-
expect(subscriptionSpy).toHaveBeenCalledTimes(1)
48-
subscriptionSpy.mockReset()
49-
50-
focusManager.setFocused(false)
51-
expect(subscriptionSpy).toHaveBeenCalledTimes(0)
52-
53-
unsubscribe()
54-
})
55-
5642
it('should return true for isFocused if document is undefined', async () => {
5743
const { document } = globalThis
5844

@@ -150,4 +136,25 @@ describe('focusManager', () => {
150136

151137
unsubscribe2()
152138
})
139+
140+
test('should call listeners when setFocused is called', () => {
141+
const listener = vi.fn()
142+
143+
focusManager.subscribe(listener)
144+
145+
focusManager.setFocused(true)
146+
focusManager.setFocused(true)
147+
148+
expect(listener).toHaveBeenCalledTimes(1)
149+
150+
focusManager.setFocused(false)
151+
focusManager.setFocused(false)
152+
153+
expect(listener).toHaveBeenCalledTimes(2)
154+
155+
focusManager.setFocused(undefined)
156+
focusManager.setFocused(undefined)
157+
158+
expect(listener).toHaveBeenCalledTimes(3)
159+
})
153160
})

packages/query-core/src/tests/onlineManager.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,25 @@ describe('onlineManager', () => {
148148

149149
unsubscribe2()
150150
})
151+
152+
test('should call listeners when setOnline is called', () => {
153+
const listener = vi.fn()
154+
155+
onlineManager.subscribe(listener)
156+
157+
onlineManager.setOnline(true)
158+
onlineManager.setOnline(true)
159+
160+
expect(listener).toHaveBeenCalledTimes(1)
161+
162+
onlineManager.setOnline(false)
163+
onlineManager.setOnline(false)
164+
165+
expect(listener).toHaveBeenCalledTimes(2)
166+
167+
onlineManager.setOnline(undefined)
168+
onlineManager.setOnline(undefined)
169+
170+
expect(listener).toHaveBeenCalledTimes(3)
171+
})
151172
})

packages/react-query/src/__tests__/useQuery.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,7 @@ describe('useQuery', () => {
36383638
})
36393639
act(() => setPrefetched(true))
36403640
}
3641+
36413642
prefetch()
36423643
}, [])
36433644

@@ -5904,6 +5905,7 @@ describe('useQuery', () => {
59045905
</div>
59055906
)
59065907
}
5908+
59075909
const rendered = renderWithClient(queryClient, <Page />)
59085910
const fetchBtn = rendered.getByRole('button', { name: 'refetch' })
59095911
await waitFor(() => rendered.getByText('data: 1'))
@@ -5964,6 +5966,7 @@ describe('useQuery', () => {
59645966
</div>
59655967
)
59665968
}
5969+
59675970
const rendered = renderWithClient(queryClient, <Page />)
59685971
await waitFor(() => rendered.getByText('status: success'))
59695972
await waitFor(() => rendered.getByText('data: 1'))

packages/vue-query/src/devtools/devtools.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { setupDevtoolsPlugin } from '@vue/devtools-api'
22
import type { CustomInspectorNode } from '@vue/devtools-api'
33
import { rankItem } from '@tanstack/match-sorter-utils'
44
import { onlineManager } from '@tanstack/query-core'
5-
import type { Query } from '@tanstack/query-core'
5+
import type { Query, QueryCacheNotifyEvent } from '@tanstack/query-core'
66
import type { QueryClient } from '../queryClient'
77
import {
88
getQueryStateLabel,
@@ -146,7 +146,13 @@ export function setupDevtools(app: any, queryClient: QueryClient) {
146146
api.sendInspectorTree(pluginId)
147147
api.sendInspectorState(pluginId)
148148

149-
if (['added', 'removed', 'updated'].includes(event.type)) {
149+
const queryEvents: QueryCacheNotifyEvent['type'][] = [
150+
'added',
151+
'removed',
152+
'updated',
153+
]
154+
155+
if (queryEvents.includes(event.type)) {
150156
api.addTimelineEvent({
151157
layerId: pluginId,
152158
event: {

0 commit comments

Comments
 (0)