fix(preact-query): allow retryOnMount when throwOnError is function by S-jooyoung · Pull Request #11166 · TanStack/query · GitHub
Skip to content

fix(preact-query): allow retryOnMount when throwOnError is function - #11166

Merged
TkDodo merged 2 commits into
TanStack:mainfrom
S-jooyoung:fix/preact-retry-on-mount-throw-on-error
Aug 20, 2026
Merged

fix(preact-query): allow retryOnMount when throwOnError is function#11166
TkDodo merged 2 commits into
TanStack:mainfrom
S-jooyoung:fix/preact-retry-on-mount-throw-on-error

Conversation

@S-jooyoung

@S-jooyoung S-jooyoung commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

Fixes #11165.

Ports #9338 to preact-query. react-query's ensurePreventErrorBoundaryRetry evaluates a function-form throwOnError against the query's actual error before disabling retryOnMount; preact-query's copy still treats any function as truthy, so throwOnError: () => false (or a predicate returning false for the current error) wrongly prevents an errored query from refetching on remount.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved retry-on-mount behavior when throwOnError is configured as a function.
    • Failed queries now correctly retry on remount when the function allows it.
    • Error handling evaluates the actual query error before deciding whether retries should be prevented.
    • Consistent behavior is now applied across individual and multiple-query usage.
  • Tests
    • Added coverage for retrying, preventing retries, and evaluating specific error messages during remounts.

Ports TanStack#9338 to preact-query: ensurePreventErrorBoundaryRetry now
receives the cached query and evaluates a function-form throwOnError
against the actual error before setting retryOnMount = false, instead
of treating any function as truthy. Includes the regression tests
from TanStack#9338, two of which fail on current main.

Fixes TanStack#11165

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/preact-query/src/errorBoundaryUtils.ts`:
- Around line 30-33: The throwOnError logic should evaluate the predicate for
every query in an error state, including failures with falsy values such as 0,
empty string, or null. Replace the query.state.error truthiness guard with the
query’s established error-status check, preserving direct option handling for
non-error states, and add coverage for a falsy rejected value.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e770acb-1a84-48ad-bfad-7ea1ea56d651

📥 Commits

Reviewing files that changed from the base of the PR and between 46d7f02 and 8948869.

📒 Files selected for processing (5)
  • .changeset/preact-retry-on-mount-throw-on-error.md
  • packages/preact-query/src/__tests__/useQuery.test.tsx
  • packages/preact-query/src/errorBoundaryUtils.ts
  • packages/preact-query/src/useBaseQuery.ts
  • packages/preact-query/src/useQueries.ts

Comment thread packages/preact-query/src/errorBoundaryUtils.ts
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nx-cloud

nx-cloud Bot commented Aug 20, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit e060a89

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 3m 49s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 8s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-20 08:53:23 UTC

@pkg-pr-new

pkg-pr-new Bot commented Aug 20, 2026

Copy link
Copy Markdown

@TkDodo
TkDodo merged commit 4913802 into TanStack:main Aug 20, 2026
9 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preact-query: retryOnMount is still disabled when a function-form throwOnError returns false (#9338 was only applied to react-query)

2 participants