fix(react-query): allow retryOnMount when throwOnError is function (#9336)
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
Summary by CodeRabbit
-
Bug Fixes
- Corrected retry-on-mount behavior when using error boundaries with throwOnError, preventing unintended retries and honoring actual error state.
- Ensured consistent behavior across single and multiple queries, including remounts and infinite stale times.
- Refined interaction with Suspense and prefetch to avoid unnecessary retries.
-
Tests
- Expanded coverage for throwOnError (boolean and function), retryOnMount, remount scenarios, and ErrorBoundary rendering to verify correct statuses, errors, and call counts.
@TkDodo Hi! Simple fix for retryOnMount when throwOnError is function. Would appreciate a review when you have time! 🙏
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
âś… Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | âś… Passed | The title clearly summarizes the main fix by specifying that retryOnMount should be allowed when throwOnError is a function, which accurately reflects the changes in errorBoundaryUtils and useQuery hooks. |
| Linked Issues Check | âś… Passed | The changes update ensurePreventErrorBoundaryRetry to distinguish between boolean and function throwOnError values, preserving retryOnMount when throwOnError is a function that returns false, and they add new tests verifying retries on remount and correct queryFn invocation counts for both function and boolean cases, thereby fulfilling the bug reproduction and expected behavior described in issue #9336. |
| Out of Scope Changes Check | ✅ Passed | All modifications are centered on refining throwOnError handling and retryOnMount logic across ensurePreventErrorBoundaryRetry, useBaseQuery, useQueries, and corresponding test cases, with no unrelated features or files altered outside the scope of the linked issue’s objectives. |
✨ Finishing touches
- [ ] 📝 Generate Docstrings
đź§Ş Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
[!TIP]
đź‘® Agentic pre-merge checks are now available in preview!
Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
- Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
- Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.
Please see the documentation for more information.
Example:
reviews: pre_merge_checks: custom_checks: - name: "Undocumented Breaking Changes" mode: "warning" instructions: | Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
⚠️ No Changeset found
Latest commit: 199fc0aa567134fc0ceafd55950fa19f2aaed9e5
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR