Skip to content

Commit 62fd9cd

Browse files
authored
Merge branch 'alpha' into alpha/fix-5538
2 parents 14703aa + 12318b4 commit 62fd9cd

File tree

33 files changed

+2273
-1498
lines changed

33 files changed

+2273
-1498
lines changed

docs/react/reference/QueryClient.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ function Component() {
527527

528528
**Options**
529529

530-
- `mutationKey: string | unknown[]`
530+
- `mutationKey: unknown[]`
531531
- `options: MutationOptions`
532532

533533
> Similar to [`setQueryDefaults`](#queryclientsetquerydefaults), the order of registration does matter here.

docs/react/reference/useMutation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mutate(variables, {
5151
- `gcTime: number | Infinity`
5252
- The time in milliseconds that unused/inactive cache data remains in memory. When a mutation's cache becomes unused or inactive, that cache data will be garbage collected after this duration. When different cache times are specified, the longest one will be used.
5353
- If set to `Infinity`, will disable garbage collection
54-
- `mutationKey: string`
54+
- `mutationKey: unknown[]`
5555
- Optional
5656
- A mutation key can be set to inherit defaults set with `queryClient.setMutationDefaults` or to identify the mutation in the devtools.
5757
- `networkMode: 'online' | 'always' | 'offlineFirst`

examples/react/react-native/src/hooks/useAppState.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { AppState, AppStateStatus } from 'react-native'
33

44
export function useAppState(onChange: (status: AppStateStatus) => void) {
55
useEffect(() => {
6-
AppState.addEventListener('change', onChange)
6+
const subscription = AppState.addEventListener('change', onChange)
77
return () => {
8-
AppState.removeEventListener('change', onChange)
8+
subscription.remove()
99
}
1010
}, [onChange])
1111
}

packages/query-async-storage-persister/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-async-storage-persister",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "A persister for asynchronous storages, to be used with TanStack/Query",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/query-broadcast-client-experimental/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-broadcast-client-experimental",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "An experimental plugin to for broadcasting the state of your queryClient between browser tabs/windows",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/query-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-core",
3-
"version": "5.0.0-alpha.66",
3+
"version": "5.0.0-alpha.70",
44
"description": "The framework agnostic core that powers TanStack Query",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/query-core/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export { CancelledError } from './retryer'
44
export { QueryCache } from './queryCache'
5+
export type { QueryCacheNotifyEvent } from './queryCache'
56
export { QueryClient } from './queryClient'
67
export { QueryObserver } from './queryObserver'
78
export { QueriesObserver } from './queriesObserver'

packages/query-core/src/infiniteQueryBehavior.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export function infiniteQueryBehavior<TQueryFnData, TError, TData>(
3939
// Get query function
4040
const queryFn =
4141
context.options.queryFn ||
42-
(() => Promise.reject(new Error('Missing queryFn')))
42+
(() =>
43+
Promise.reject(
44+
new Error(`Missing queryFn: '${context.options.queryHash}'`),
45+
))
4346

4447
// Create function to fetch a page
4548
const fetchPage = async (

packages/query-core/src/notifyManager.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ type NotifyFunction = (callback: () => void) => void
88

99
type BatchNotifyFunction = (callback: () => void) => void
1010

11+
type BatchCallsCallback<T extends unknown[]> = (...args: T) => void
12+
1113
export function createNotifyManager() {
1214
let queue: NotifyCallback[] = []
1315
let transactions = 0
@@ -45,12 +47,14 @@ export function createNotifyManager() {
4547
/**
4648
* All calls to the wrapped function will be batched.
4749
*/
48-
const batchCalls = <T extends Function>(callback: T): T => {
49-
return ((...args: any[]) => {
50+
const batchCalls = <T extends unknown[]>(
51+
callback: BatchCallsCallback<T>,
52+
): BatchCallsCallback<T> => {
53+
return (...args) => {
5054
schedule(() => {
5155
callback(...args)
5256
})
53-
}) as any
57+
}
5458
}
5559

5660
const flush = (): void => {

packages/query-core/src/query.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,9 @@ export class Query<
387387
// Create fetch function
388388
const fetchFn = () => {
389389
if (!this.options.queryFn) {
390-
return Promise.reject(new Error('Missing queryFn'))
390+
return Promise.reject(
391+
new Error(`Missing queryFn: '${this.options.queryHash}'`),
392+
)
391393
}
392394
this.#abortSignalConsumed = false
393395
return this.options.queryFn(

packages/query-core/src/queryCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ interface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {
6868
observer: QueryObserver<any, any, any, any, any>
6969
}
7070

71-
type QueryCacheNotifyEvent =
71+
export type QueryCacheNotifyEvent =
7272
| NotifyEventQueryAdded
7373
| NotifyEventQueryRemoved
7474
| NotifyEventQueryUpdated

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { waitFor } from '@testing-library/react'
2-
import type { QueryClient, InfiniteQueryObserverResult } from '..'
2+
import type { QueryClient, QueryCache, InfiniteQueryObserverResult } from '..'
33
import { InfiniteQueryObserver, CancelledError } from '..'
44
import { createQueryClient, queryKey, sleep } from './utils'
55
import { vi } from 'vitest'
66

77
describe('InfiniteQueryBehavior', () => {
88
let queryClient: QueryClient
9+
let queryCache: QueryCache
910

1011
beforeEach(() => {
1112
queryClient = createQueryClient()
13+
queryCache = queryClient.getQueryCache()
1214
queryClient.mount()
1315
})
1416

@@ -35,9 +37,10 @@ describe('InfiniteQueryBehavior', () => {
3537
})
3638

3739
await waitFor(() => {
40+
const query = queryCache.find({ queryKey: key })!
3841
return expect(observerResult).toMatchObject({
3942
isError: true,
40-
error: new Error('Missing queryFn'),
43+
error: new Error(`Missing queryFn: '${query.queryHash}'`),
4144
})
4245
})
4346

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

+15
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,19 @@ describe('notifyManager', () => {
4949

5050
expect(notifySpy).toHaveBeenCalledTimes(1)
5151
})
52+
53+
it('typedefs should catch proper signatures', async () => {
54+
const notifyManagerTest = createNotifyManager()
55+
56+
// we define some fn with its signature:
57+
const fn: (a: string, b: number) => string = (a, b) => a + b
58+
59+
//now somefn expect to be called with args [a: string, b: number]
60+
const someFn = notifyManagerTest.batchCalls(fn)
61+
62+
someFn('im happy', 4)
63+
64+
//@ts-expect-error
65+
someFn('im not happy', false)
66+
})
5267
})

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,12 @@ describe('query', () => {
761761
})
762762

763763
const unsubscribe = observer.subscribe(() => undefined)
764+
764765
await sleep(10)
766+
const query = queryCache.find({ queryKey: key })!
765767
expect(observer.getCurrentResult()).toMatchObject({
766768
status: 'error',
767-
error: new Error('Missing queryFn'),
769+
error: new Error(`Missing queryFn: '${query.queryHash}'`),
768770
})
769771
unsubscribe()
770772
})

packages/query-persist-client-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-persist-client-core",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "Set of utilities for interacting with persisters, which can save your queryClient for later use",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/query-sync-storage-persister/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/query-sync-storage-persister",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "A persister for synchronous storages, to be used with TanStack/Query",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/react-query-devtools/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/react-query-devtools",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "Developer tools to interact with and visualize the TanStack/react-query cache",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/react-query-persist-client/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/react-query-persist-client",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "React bindings to work with persisters in TanStack/react-query",
55
"author": "tannerlinsley",
66
"license": "MIT",
@@ -40,7 +40,8 @@
4040
"build:types": "tsc --emitDeclarationOnly"
4141
},
4242
"dependencies": {
43-
"@tanstack/query-persist-client-core": "workspace:*"
43+
"@tanstack/query-persist-client-core": "workspace:*",
44+
"client-only": "0.0.1"
4445
},
4546
"devDependencies": {
4647
"@tanstack/react-query": "workspace:*",

packages/react-query-persist-client/src/PersistQueryClientProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import * as React from 'react'
33

44
import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'

packages/react-query/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/react-query",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
55
"author": "tannerlinsley",
66
"license": "MIT",
@@ -45,7 +45,8 @@
4545
"!build/codemods/**/__tests__"
4646
],
4747
"dependencies": {
48-
"@tanstack/query-core": "workspace:*"
48+
"@tanstack/query-core": "workspace:*",
49+
"client-only": "0.0.1"
4950
},
5051
"devDependencies": {
5152
"@types/react": "^18.2.4",

packages/react-query/src/QueryClientProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import * as React from 'react'
33

44
import type { QueryClient } from '@tanstack/query-core'

packages/react-query/src/useBaseQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import * as React from 'react'
33

44
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'

packages/react-query/src/useInfiniteQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import type {
33
QueryObserver,
44
QueryKey,

packages/react-query/src/useIsFetching.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import * as React from 'react'
33
import type { QueryClient, QueryFilters } from '@tanstack/query-core'
44
import { notifyManager } from '@tanstack/query-core'

packages/react-query/src/useMutation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import * as React from 'react'
33
import type { QueryClient, DefaultError } from '@tanstack/query-core'
44
import { notifyManager, MutationObserver } from '@tanstack/query-core'

packages/react-query/src/useMutationState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import * as React from 'react'
33

44
import type {

packages/react-query/src/useQueries.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import * as React from 'react'
33

44
import type {

packages/react-query/src/useQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use client'
1+
import 'client-only'
22
import type { QueryClient, QueryKey, DefaultError } from '@tanstack/query-core'
33
import { QueryObserver } from '@tanstack/query-core'
44
import type {

packages/solid-query/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/solid-query",
3-
"version": "5.0.0-alpha.69",
3+
"version": "5.0.0-alpha.70",
44
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
55
"author": "tannerlinsley",
66
"license": "MIT",

packages/svelte-query-devtools/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/svelte-query-devtools",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "Developer tools to interact with and visualize the TanStack/svelte-query cache",
55
"author": "Lachlan Collins",
66
"license": "MIT",

packages/svelte-query/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/svelte-query",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
55
"author": "Lachlan Collins",
66
"license": "MIT",

packages/vue-query/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/vue-query",
3-
"version": "5.0.0-alpha.68",
3+
"version": "5.0.0-alpha.70",
44
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Vue",
55
"author": "Damian Osipiuk",
66
"license": "MIT",

0 commit comments

Comments
 (0)