Skip to content

Commit 18c7a41

Browse files
authored
feat: rename throwErrors to throwOnError (#5318)
* feat: rename throwErrors to throwOnError to be aligned with the options we already have on imperative methods, like `invalidateQueries` * docs: fix outdated code reference * chore: rename type * fix: let the refetchInterval function also return undefined and fall back to false if it does
1 parent 8c69c5e commit 18c7a41

24 files changed

+94
-92
lines changed

docs/react/guides/migrating-to-v5.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ const queryClient = new QueryClient({
202202
})
203203
```
204204

205-
### The `useErrorBoundary` option has been renamed to `throwErrors`
205+
### The `useErrorBoundary` option has been renamed to `throwOnError`
206206

207-
To make the `useErrorBoundary` option more framework-agnostic and avoid confusion with the established React function prefix "`use`" for hooks and the "ErrorBoundary" component name, it has been renamed to `throwErrors` to more accurately reflect its functionality.
207+
To make the `useErrorBoundary` option more framework-agnostic and avoid confusion with the established React function prefix "`use`" for hooks and the "ErrorBoundary" component name, it has been renamed to `throwOnError` to more accurately reflect its functionality.
208208

209209
### TypeScript: `Error` is now the default type for errors instead of `unknown`
210210

docs/react/guides/suspense.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ useQuery({ queryKey, queryFn, suspense: true })
4141

4242
When using suspense mode, `status` states and `error` objects are not needed and are then replaced by usage of the `React.Suspense` component (including the use of the `fallback` prop and React error boundaries for catching errors). Please read the [Resetting Error Boundaries](#resetting-error-boundaries) and look at the [Suspense Example](https://codesandbox.io/s/github/tannerlinsley/react-query/tree/main/examples/react/suspense) for more information on how to set up suspense mode.
4343

44-
In addition to queries behaving differently in suspense mode, mutations also behave a bit differently. By default, instead of supplying the `error` variable when a mutation fails, it will be thrown during the next render of the component it's used in and propagate to the nearest error boundary, similar to query errors. If you wish to disable this, you can set the `throwErrors` option to `false`. If you wish that errors are not thrown at all, you can set the `throwOnError` option to `false` as well!
44+
In addition to queries behaving differently in suspense mode, mutations also behave a bit differently. By default, instead of supplying the `error` variable when a mutation fails, it will be thrown during the next render of the component it's used in and propagate to the nearest error boundary, similar to query errors. If you wish to disable this, you can set the `throwOnError` option to `false`. If you wish that errors are not thrown at all, you can set the `throwOnError` option to `false` as well!
4545

4646
## Resetting Error Boundaries
4747

48-
Whether you are using **suspense** or **throwErrors** in your queries, you will need a way to let queries know that you want to try again when re-rendering after some error occurred.
48+
Whether you are using **suspense** or **throwOnError** in your queries, you will need a way to let queries know that you want to try again when re-rendering after some error occurred.
4949

5050
Query errors can be reset with the `QueryErrorResetBoundary` component or with the `useQueryErrorResetBoundary` hook.
5151

docs/react/reference/QueryClient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ try {
9191

9292
**Options**
9393

94-
The options for `fetchQuery` are exactly the same as those of [`useQuery`](../reference/useQuery), except the following: `enabled, refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnReconnect, notifyOnChangeProps, onSuccess, onError, onSettled, throwErrors, select, suspense, placeholderData`; which are strictly for useQuery and useInfiniteQuery. You can check the [source code](https://github.com/tannerlinsley/react-query/blob/361935a12cec6f36d0bd6ba12e84136c405047c5/src/core/types.ts#L83) for more clarity.
94+
The options for `fetchQuery` are exactly the same as those of [`useQuery`](../reference/useQuery), except the following: `enabled, refetchInterval, refetchIntervalInBackground, refetchOnWindowFocus, refetchOnReconnect, refetchOnMount, notifyOnChangeProps, throwOnError, select, suspense, placeholderData`; which are strictly for useQuery and useInfiniteQuery. You can check the [source code](https://github.com/TanStack/query/blob/7cd2d192e6da3df0b08e334ea1cf04cd70478827/packages/query-core/src/types.ts#L119) for more clarity.
9595

9696
**Returns**
9797

docs/react/reference/QueryErrorResetBoundary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id: QueryErrorResetBoundary
33
title: QueryErrorResetBoundary
44
---
55

6-
When using **suspense** or **throwErrors** in your queries, you need a way to let queries know that you want to try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can reset any query errors within the boundaries of the component.
6+
When using **suspense** or **throwOnError** in your queries, you need a way to let queries know that you want to try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can reset any query errors within the boundaries of the component.
77

88
```tsx
99
import { QueryErrorResetBoundary } from '@tanstack/react-query'

docs/react/reference/useMutation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const {
3131
onSuccess,
3232
retry,
3333
retryDelay,
34-
throwErrors,
34+
throwOnError,
3535
meta,
3636
})
3737

@@ -84,8 +84,8 @@ mutate(variables, {
8484
- This function receives a `retryAttempt` integer and the actual Error and returns the delay to apply before the next attempt in milliseconds.
8585
- A function like `attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000)` applies exponential backoff.
8686
- A function like `attempt => attempt * 1000` applies linear backoff.
87-
- `throwErrors: undefined | boolean | (error: TError) => boolean`
88-
- Defaults to the global query config's `throwErrors` value, which is `undefined`
87+
- `throwOnError: undefined | boolean | (error: TError) => boolean`
88+
- Defaults to the global query config's `throwOnError` value, which is `undefined`
8989
- Set this to `true` if you want mutation errors to be thrown in the render phase and propagate to the nearest error boundary
9090
- Set this to `false` to disable the behavior of throwing errors to the error boundary.
9191
- If set to a function, it will be passed the error and should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`)

docs/react/reference/useQuery.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const {
5656
staleTime,
5757
structuralSharing,
5858
suspense,
59-
throwErrors,
59+
throwOnError,
6060
})
6161
```
6262

@@ -101,7 +101,7 @@ const {
101101
- `queryKeyHashFn: (queryKey: QueryKey) => string`
102102
- Optional
103103
- If specified, this function is used to hash the `queryKey` to a string.
104-
- `refetchInterval: number | false | ((data: TData | undefined, query: Query) => number | false)`
104+
- `refetchInterval: number | false | ((data: TData | undefined, query: Query) => number | false | undefined)`
105105
- Optional
106106
- If set to a number, all queries will continuously refetch at this frequency in milliseconds
107107
- If set to a function, the function will be executed with the latest data and query to compute a frequency
@@ -171,8 +171,8 @@ const {
171171
- Defaults to `true`
172172
- If set to `false`, structural sharing between query results will be disabled.
173173
- If set to a function, the old and new data values will be passed through this function, which should combine them into resolved data for the query. This way, you can retain references from the old data to improve performance even when that data contains non-serializable values.
174-
- `throwErrors: undefined | boolean | (error: TError, query: Query) => boolean`
175-
- Defaults to the global query config's `throwErrors` value, which is `undefined`
174+
- `throwOnError: undefined | boolean | (error: TError, query: Query) => boolean`
175+
- Defaults to the global query config's `throwOnError` value, which is `undefined`
176176
- Set this to `true` if you want errors to be thrown in the render phase and propagate to the nearest error boundary
177177
- Set this to `false` to disable `suspense`'s default behavior of throwing errors to the error boundary.
178178
- If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`)

docs/solid/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,6 @@ function App() {
225225
```
226226

227227
- Errors can be caught and reset using SolidJS' native `ErrorBoundary` component.
228-
Set `throwErrors` or the `suspense` option to `true` to make sure errors are thrown to the `ErrorBoundary`
228+
Set `throwOnError` or the `suspense` option to `true` to make sure errors are thrown to the `ErrorBoundary`
229229

230230
- Since Property tracking is handled through Solid's fine grained reactivity, options like `notifyOnChangeProps` are not needed

packages/query-core/src/queryClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ export class QueryClient {
478478
defaultedOptions.refetchOnReconnect =
479479
defaultedOptions.networkMode !== 'always'
480480
}
481-
if (typeof defaultedOptions.throwErrors === 'undefined') {
482-
defaultedOptions.throwErrors = !!defaultedOptions.suspense
481+
if (typeof defaultedOptions.throwOnError === 'undefined') {
482+
defaultedOptions.throwOnError = !!defaultedOptions.suspense
483483
}
484484

485485
return defaultedOptions as DefaultedQueryObserverOptions<

packages/query-core/src/queryObserver.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,14 @@ export class QueryObserver<
342342
}
343343

344344
#computeRefetchInterval() {
345-
return typeof this.options.refetchInterval === 'function'
346-
? this.options.refetchInterval(
347-
this.#currentResult.data,
348-
this.#currentQuery,
349-
)
350-
: this.options.refetchInterval ?? false
345+
return (
346+
(typeof this.options.refetchInterval === 'function'
347+
? this.options.refetchInterval(
348+
this.#currentResult.data,
349+
this.#currentQuery,
350+
)
351+
: this.options.refetchInterval) ?? false
352+
)
351353
}
352354

353355
#updateRefetchInterval(nextInterval: number | false): void {
@@ -593,7 +595,7 @@ export class QueryObserver<
593595

594596
const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps)
595597

596-
if (this.options.throwErrors) {
598+
if (this.options.throwOnError) {
597599
includedProps.add('error')
598600
}
599601

packages/query-core/src/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export interface InfiniteQueryPageParamsOptions<
154154
getNextPageParam: GetNextPageParamFunction<TPageParam, TQueryFnData>
155155
}
156156

157-
export type ThrowErrors<
157+
export type ThrowOnError<
158158
TQueryFnData,
159159
TError,
160160
TQueryData,
@@ -202,7 +202,7 @@ export interface QueryObserverOptions<
202202
| ((
203203
data: TData | undefined,
204204
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
205-
) => number | false)
205+
) => number | false | undefined)
206206
/**
207207
* If set to `true`, the query will continue to refetch while their tab/window is in the background.
208208
* Defaults to `false`.
@@ -266,7 +266,7 @@ export interface QueryObserverOptions<
266266
* If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`).
267267
* Defaults to `false`.
268268
*/
269-
throwErrors?: ThrowErrors<TQueryFnData, TError, TQueryData, TQueryKey>
269+
throwOnError?: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>
270270
/**
271271
* This option can be used to transform or select a part of the data returned by the query function.
272272
*/
@@ -297,7 +297,7 @@ export type DefaultedQueryObserverOptions<
297297
TQueryKey extends QueryKey = QueryKey,
298298
> = WithRequired<
299299
QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
300-
'throwErrors' | 'refetchOnReconnect'
300+
'throwOnError' | 'refetchOnReconnect'
301301
>
302302

303303
export interface InfiniteQueryObserverOptions<
@@ -333,7 +333,7 @@ export type DefaultedInfiniteQueryObserverOptions<
333333
TQueryKey,
334334
TPageParam
335335
>,
336-
'throwErrors' | 'refetchOnReconnect'
336+
'throwOnError' | 'refetchOnReconnect'
337337
>
338338

339339
export interface FetchQueryOptions<
@@ -636,7 +636,7 @@ export interface MutationObserverOptions<
636636
TVariables = void,
637637
TContext = unknown,
638638
> extends MutationOptions<TData, TError, TVariables, TContext> {
639-
throwErrors?: boolean | ((error: TError) => boolean)
639+
throwOnError?: boolean | ((error: TError) => boolean)
640640
}
641641

642642
export interface MutateOptions<

0 commit comments

Comments
 (0)