Skip to content

fix(react-query): allow retryOnMount when throwOnError is function (#9336) #9338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Han5991
Copy link

@Han5991 Han5991 commented Jun 30, 2025

Fixed #9336

Summary

  • Fixed throwOnError retry logic to properly handle function vs boolean values
  • When throwOnError is a function, allow retryOnMount to proceed even when error boundary hasn't been reset
  • Maintains existing prevention behavior for boolean throwOnError values
  • Added comprehensive test coverage for the retry behavior

Han5991 added 2 commits June 30, 2025 23:43
…cases

When throwOnError is a function, allow retryOnMount to proceed even when error boundary hasn't reset,
while maintaining the prevention behavior for boolean throwOnError values.
options.experimental_prefetchInRender
) {
// Prevent retrying failed query if the error boundary has not been reset yet
if (!errorResetBoundary.isReset()) {
options.retryOnMount = false
}
} else if (options.throwOnError) {
if (!errorResetBoundary.isReset() && typeof options.throwOnError !== 'function') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function can return true or false so I think we'd need to evaluate it to get the result

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to evaluate the throwOnError function result instead of just checking if it's a function. Thanks for the feedback!

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.
@Han5991 Han5991 requested a review from TkDodo June 30, 2025 15:24
Han5991 added 2 commits July 6, 2025 09:59
This commit introduces tests to verify the behavior of the `throwOnError` callback in scenarios where `retryOnMount` is enabled. It ensures proper handling of retries based on the error state and the `throwOnError` function's return value. These tests improve the reliability and coverage of error handling logic in `useQuery`.
- Pass query object to ensurePreventErrorBoundaryRetry for accurate state checking
- Preserve query deduplication behavior while fixing throwOnError function handling
- Fixes issue where throwOnError function couldn't access query error state
@Han5991 Han5991 force-pushed the fix/usequery-retry-on-mount-with-throw-on-error-issue(#9336) branch from f7b90c2 to 9c8516d Compare July 6, 2025 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useQuery does not perform a retry on mount when the function provided to throwOnError returns false, even if retryOnMount: true is set
2 participants