Skip to content

Commit

Permalink
Merge branch 'alpha' into alpha/fix-5538
Browse files Browse the repository at this point in the history
  • Loading branch information
TkDodo authored Jun 26, 2023
2 parents 78d45f7 + 12318b4 commit 8a4853b
Show file tree
Hide file tree
Showing 33 changed files with 2,273 additions and 1,498 deletions.
2 changes: 1 addition & 1 deletion docs/react/reference/QueryClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ function Component() {

**Options**

- `mutationKey: string | unknown[]`
- `mutationKey: unknown[]`
- `options: MutationOptions`

> Similar to [`setQueryDefaults`](#queryclientsetquerydefaults), the order of registration does matter here.
Expand Down
2 changes: 1 addition & 1 deletion docs/react/reference/useMutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mutate(variables, {
- `gcTime: number | Infinity`
- 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.
- If set to `Infinity`, will disable garbage collection
- `mutationKey: string`
- `mutationKey: unknown[]`
- Optional
- A mutation key can be set to inherit defaults set with `queryClient.setMutationDefaults` or to identify the mutation in the devtools.
- `networkMode: 'online' | 'always' | 'offlineFirst`
Expand Down
4 changes: 2 additions & 2 deletions examples/react/react-native/src/hooks/useAppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { AppState, AppStateStatus } from 'react-native'

export function useAppState(onChange: (status: AppStateStatus) => void) {
useEffect(() => {
AppState.addEventListener('change', onChange)
const subscription = AppState.addEventListener('change', onChange)
return () => {
AppState.removeEventListener('change', onChange)
subscription.remove()
}
}, [onChange])
}
2 changes: 1 addition & 1 deletion packages/query-async-storage-persister/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-async-storage-persister",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "A persister for asynchronous storages, to be used with TanStack/Query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/query-broadcast-client-experimental/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-broadcast-client-experimental",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "An experimental plugin to for broadcasting the state of your queryClient between browser tabs/windows",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-core",
"version": "5.0.0-alpha.66",
"version": "5.0.0-alpha.70",
"description": "The framework agnostic core that powers TanStack Query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions packages/query-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export { CancelledError } from './retryer'
export { QueryCache } from './queryCache'
export type { QueryCacheNotifyEvent } from './queryCache'
export { QueryClient } from './queryClient'
export { QueryObserver } from './queryObserver'
export { QueriesObserver } from './queriesObserver'
Expand Down
5 changes: 4 additions & 1 deletion packages/query-core/src/infiniteQueryBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export function infiniteQueryBehavior<TQueryFnData, TError, TData>(
// Get query function
const queryFn =
context.options.queryFn ||
(() => Promise.reject(new Error('Missing queryFn')))
(() =>
Promise.reject(
new Error(`Missing queryFn: '${context.options.queryHash}'`),
))

// Create function to fetch a page
const fetchPage = async (
Expand Down
10 changes: 7 additions & 3 deletions packages/query-core/src/notifyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type NotifyFunction = (callback: () => void) => void

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

type BatchCallsCallback<T extends unknown[]> = (...args: T) => void

export function createNotifyManager() {
let queue: NotifyCallback[] = []
let transactions = 0
Expand Down Expand Up @@ -45,12 +47,14 @@ export function createNotifyManager() {
/**
* All calls to the wrapped function will be batched.
*/
const batchCalls = <T extends Function>(callback: T): T => {
return ((...args: any[]) => {
const batchCalls = <T extends unknown[]>(
callback: BatchCallsCallback<T>,
): BatchCallsCallback<T> => {
return (...args) => {
schedule(() => {
callback(...args)
})
}) as any
}
}

const flush = (): void => {
Expand Down
4 changes: 3 additions & 1 deletion packages/query-core/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ export class Query<
// Create fetch function
const fetchFn = () => {
if (!this.options.queryFn) {
return Promise.reject(new Error('Missing queryFn'))
return Promise.reject(
new Error(`Missing queryFn: '${this.options.queryHash}'`),
)
}
this.#abortSignalConsumed = false
return this.options.queryFn(
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/src/queryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ interface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {
observer: QueryObserver<any, any, any, any, any>
}

type QueryCacheNotifyEvent =
export type QueryCacheNotifyEvent =
| NotifyEventQueryAdded
| NotifyEventQueryRemoved
| NotifyEventQueryUpdated
Expand Down
7 changes: 5 additions & 2 deletions packages/query-core/src/tests/infiniteQueryBehavior.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { waitFor } from '@testing-library/react'
import type { QueryClient, InfiniteQueryObserverResult } from '..'
import type { QueryClient, QueryCache, InfiniteQueryObserverResult } from '..'
import { InfiniteQueryObserver, CancelledError } from '..'
import { createQueryClient, queryKey, sleep } from './utils'
import { vi } from 'vitest'

describe('InfiniteQueryBehavior', () => {
let queryClient: QueryClient
let queryCache: QueryCache

beforeEach(() => {
queryClient = createQueryClient()
queryCache = queryClient.getQueryCache()
queryClient.mount()
})

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

await waitFor(() => {
const query = queryCache.find({ queryKey: key })!
return expect(observerResult).toMatchObject({
isError: true,
error: new Error('Missing queryFn'),
error: new Error(`Missing queryFn: '${query.queryHash}'`),
})
})

Expand Down
15 changes: 15 additions & 0 deletions packages/query-core/src/tests/notifyManager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ describe('notifyManager', () => {

expect(notifySpy).toHaveBeenCalledTimes(1)
})

it('typedefs should catch proper signatures', async () => {
const notifyManagerTest = createNotifyManager()

// we define some fn with its signature:
const fn: (a: string, b: number) => string = (a, b) => a + b

//now somefn expect to be called with args [a: string, b: number]
const someFn = notifyManagerTest.batchCalls(fn)

someFn('im happy', 4)

//@ts-expect-error
someFn('im not happy', false)
})
})
4 changes: 3 additions & 1 deletion packages/query-core/src/tests/query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,12 @@ describe('query', () => {
})

const unsubscribe = observer.subscribe(() => undefined)

await sleep(10)
const query = queryCache.find({ queryKey: key })!
expect(observer.getCurrentResult()).toMatchObject({
status: 'error',
error: new Error('Missing queryFn'),
error: new Error(`Missing queryFn: '${query.queryHash}'`),
})
unsubscribe()
})
Expand Down
2 changes: 1 addition & 1 deletion packages/query-persist-client-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-persist-client-core",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "Set of utilities for interacting with persisters, which can save your queryClient for later use",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/query-sync-storage-persister/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-sync-storage-persister",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "A persister for synchronous storages, to be used with TanStack/Query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/react-query-devtools",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "Developer tools to interact with and visualize the TanStack/react-query cache",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
5 changes: 3 additions & 2 deletions packages/react-query-persist-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/react-query-persist-client",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "React bindings to work with persisters in TanStack/react-query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down Expand Up @@ -40,7 +40,8 @@
"build:types": "tsc --emitDeclarationOnly"
},
"dependencies": {
"@tanstack/query-persist-client-core": "workspace:*"
"@tanstack/query-persist-client-core": "workspace:*",
"client-only": "0.0.1"
},
"devDependencies": {
"@tanstack/react-query": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import * as React from 'react'

import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
Expand Down
5 changes: 3 additions & 2 deletions packages/react-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/react-query",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
"author": "tannerlinsley",
"license": "MIT",
Expand Down Expand Up @@ -45,7 +45,8 @@
"!build/codemods/**/__tests__"
],
"dependencies": {
"@tanstack/query-core": "workspace:*"
"@tanstack/query-core": "workspace:*",
"client-only": "0.0.1"
},
"devDependencies": {
"@types/react": "^18.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/QueryClientProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import * as React from 'react'

import type { QueryClient } from '@tanstack/query-core'
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/useBaseQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import * as React from 'react'

import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/useInfiniteQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import type {
QueryObserver,
QueryKey,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/useIsFetching.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import * as React from 'react'
import type { QueryClient, QueryFilters } from '@tanstack/query-core'
import { notifyManager } from '@tanstack/query-core'
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/useMutation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import * as React from 'react'
import type { QueryClient, DefaultError } from '@tanstack/query-core'
import { notifyManager, MutationObserver } from '@tanstack/query-core'
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/useMutationState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import * as React from 'react'

import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/useQueries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import * as React from 'react'

import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
import 'client-only'
import type { QueryClient, QueryKey, DefaultError } from '@tanstack/query-core'
import { QueryObserver } from '@tanstack/query-core'
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/solid-query",
"version": "5.0.0-alpha.69",
"version": "5.0.0-alpha.70",
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-query-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/svelte-query-devtools",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "Developer tools to interact with and visualize the TanStack/svelte-query cache",
"author": "Lachlan Collins",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/svelte-query",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
"author": "Lachlan Collins",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/vue-query",
"version": "5.0.0-alpha.68",
"version": "5.0.0-alpha.70",
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Vue",
"author": "Damian Osipiuk",
"license": "MIT",
Expand Down
Loading

0 comments on commit 8a4853b

Please sign in to comment.