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-jooyoungS-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.
FixesTanStack#11165
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitaiBot commented Aug 10, 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8eb5203a-254e-4ec4-b7ec-e8b01a079364

📥 Commits

Reviewing files that changed from the base of the PR and between 3c79861 and e060a89.

📒 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
🚧 Files skipped from review as they are similar to previous changes (5)
  • .changeset/preact-retry-on-mount-throw-on-error.md
  • packages/preact-query/src/useQueries.ts
  • packages/preact-query/src/errorBoundaryUtils.ts
  • packages/preact-query/src/useBaseQuery.ts
  • packages/preact-query/src/tests/useQuery.test.tsx

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


📝 Walkthrough

Walkthrough

Preact Query now evaluates functional throwOnError values against the cached query error before disabling retryOnMount. Cached query retrieval is reused across error-boundary and prefetch handling. Tests cover false, true, and error-specific predicates.

Changes

Preact retry-on-mount error handling

Layer / File(s)Summary
Resolve throwOnError from cached query state
packages/preact-query/src/errorBoundaryUtils.ts, packages/preact-query/src/useBaseQuery.ts
ensurePreventErrorBoundaryRetry receives the cached query and resolves functional throwOnError values with the actual query error. useBaseQuery reuses the cached query for error-boundary checks and prefetch promises.
Wire query hooks and validate retry behavior
packages/preact-query/src/useQueries.ts, packages/preact-query/src/__tests__/useQuery.test.tsx, .changeset/preact-retry-on-mount-throw-on-error.md
useQueries passes each cached query to error-boundary handling. Tests cover functional predicates that return false, return true, or inspect the actual error. The changeset records the patch.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk:⚪ Minimal · up to e060a

This change corrects retry-on-remount behavior for function-based error handling and adds regression coverage; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
participant useBaseQuery
participant QueryCache
participant ensurePreventErrorBoundaryRetry
participant shouldThrowError
useBaseQuery->>QueryCache: Retrieve cached query by queryHash
useBaseQuery->>ensurePreventErrorBoundaryRetry: Pass options, reset boundary, and query
ensurePreventErrorBoundaryRetry->>shouldThrowError: Evaluate throwOnError with query.error and query
shouldThrowError-->>ensurePreventErrorBoundaryRetry: Return resolved boolean
ensurePreventErrorBoundaryRetry->>useBaseQuery: Apply retryOnMount prevention when resolved value is true
Loading

Possibly related PRs

Suggested reviewers:tkdodo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly identifies the main fix: allowing retryOnMount when functional throwOnError returns false.
Description check✅ PassedThe description includes the required changes, checklist, release impact, motivation, implementation details, and test coverage.
Linked Issues check✅ PassedThe changes satisfy issue #11165 by evaluating functional throwOnError against the actual error and adding matching regression tests.
Out of Scope Changes check✅ PassedThe modified source files, tests, and changeset directly support the linked issue and stated parity objectives.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@coderabbitaicoderabbitaiBot 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 threadpackages/preact-query/src/errorBoundaryUtils.ts
@coderabbitai

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-cloudBot commented Aug 20, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit e060a89

CommandStatusDurationResult
nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded3m 49sView ↗
nx run-many --target=build --exclude=examples/*...✅ Succeeded8sView ↗

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

@pkg-pr-new

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@11166

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@11166

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@11166

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@11166

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@11166

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11166

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@11166

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@11166

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@11166

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@11166

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@11166

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11166

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@11166

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@11166

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@11166

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@11166

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@11166

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@11166

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@11166

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@11166

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@11166

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@11166

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@11166

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@11166

commit: e060a89

@TkDodo
TkDodo merged commit 4913802 into TanStack:mainAug 20, 2026
9 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Aug 20, 2026
Sign up for freeto 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

@S-jooyoung@TkDodo