Skip to content

Commit b79395d

Browse files
committed
fix(react-query): enhance throwOnError logic in error boundaries
Refine behavior to handle function-type throwOnError, allowing retries when appropriate. Ensure boolean throwOnError values still prevent retries when the error boundary isn't reset.
1 parent 9b4d31b commit b79395d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/react-query/src/errorBoundaryUtils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const ensurePreventErrorBoundaryRetry = <
2525
TQueryKey
2626
>,
2727
errorResetBoundary: QueryErrorResetBoundaryValue,
28+
query?: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
2829
) => {
2930
if (
3031
options.suspense ||
@@ -34,8 +35,12 @@ export const ensurePreventErrorBoundaryRetry = <
3435
if (!errorResetBoundary.isReset()) {
3536
options.retryOnMount = false
3637
}
37-
} else if (options.throwOnError) {
38-
if (!errorResetBoundary.isReset() && typeof options.throwOnError !== 'function') {
38+
} else if (options.throwOnError && !errorResetBoundary.isReset()) {
39+
if (typeof options.throwOnError === 'function') {
40+
if (query?.state.error && shouldThrowError(options.throwOnError, [query.state.error, query])) {
41+
options.retryOnMount = false
42+
}
43+
} else {
3944
options.retryOnMount = false
4045
}
4146
}

0 commit comments

Comments
 (0)