Skip to content

fix(react-query): retry queries with falsy errors on mount - #11328

Open
jeonghoon11 wants to merge 1 commit into
TanStack:mainfrom
jeonghoon11:fix/react-qeury-falsy-error-retry-on-mount
Open

fix(react-query): retry queries with falsy errors on mount#11328
jeonghoon11 wants to merge 1 commit into
TanStack:mainfrom
jeonghoon11:fix/react-qeury-falsy-error-retry-on-mount

Conversation

@jeonghoon11

@jeonghoon11 jeonghoon11 commented Aug 29, 2026

Copy link
Copy Markdown

Fixes #11327

🎯 Changes

When a query rejected with a falsy value such as undefined, ensurePreventErrorBoundaryRetry did not evaluate the function-valued throwOnError option because it checked the truthiness of
query.state.error.

The callback function itself was then treated as truthy, causing retryOnMount to be set to false even when throwOnError would return false.

This change checks query.state.status === 'error' instead, ensuring that the throwOnError callback is evaluated for all query errors, including falsy ones.

A regression test verifies that a query rejecting with undefined retries after remounting when throwOnError returns false.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed queries that fail with an empty or falsy error so they correctly retry when mounted again.
    • Improved handling of throwOnError: false together with retryOnMount: true, ensuring failed queries can retry as configured.
  • Release

    • Included in a patch release of @tanstack/react-query.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8cad0103-a558-43ff-8b64-cc2e3ca644f9

📥 提交

Reviewing files that changed from the base of the PR and between 2969edf and 5c05f30.

📒 Files selected for processing (3)
  • .changeset/fuzzy-rats-mutate.md
  • packages/react-query/src/__tests__/useQuery.test.tsx
  • packages/react-query/src/errorBoundaryUtils.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The retry prevention logic now checks query status instead of error truthiness. A regression test verifies remount retries for a falsy rejected error. A patch changeset documents the behavior.

Changes

Falsy error retry behavior

Layer / File(s) Summary
Retry status gate and regression coverage
packages/react-query/src/errorBoundaryUtils.ts, packages/react-query/src/__tests__/useQuery.test.tsx, .changeset/fuzzy-rats-mutate.md
ensurePreventErrorBoundaryRetry evaluates functional throwOnError when the query status is error, including falsy errors. The test verifies a second query invocation after remount. The changeset declares a patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 5c05f

This change restores retry-on-remount behavior when queries reject with falsy errors and the configured error policy allows retrying. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: tkdodo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked 问题 check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: retrying React Query queries with falsy errors on mount.
Description check ✅ Passed The description explains the cause, implementation, regression coverage, checklist status, and release impact. The test checklist item is unchecked, but the description is otherwise complete and inclu…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description explains the cause, implementation, regression coverage, checklist status, and release impact. The test checklist item is unchecked, but the description is otherwise complete and includes a generated changeset.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

注册 for free to join this conversation on GitHub. Already have an account? 登录 to comment

标签

None yet

项目

None yet

Development

Successfully merging this pull request may close these issues.

Falsy query errors disable retryOnMount when throwOnError returns false

1 participant