Skip to content

fix(preact-query): propagate falsy errors from useMutation to the error boundary - #11312

Open
yogesh968 wants to merge 1 commit into
TanStack:mainfrom
yogesh968:fix/preact-mutation-falsy-error
Open

fix(preact-query): propagate falsy errors from useMutation to the error boundary#11312
yogesh968 wants to merge 1 commit into
TanStack:mainfrom
yogesh968:fix/preact-mutation-falsy-error

Conversation

@yogesh968

@yogesh968 yogesh968 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Same bug as #11311, in the Preact adapter.

useMutation gates the error boundary throw on the error value itself being truthy:

if (
  result.error &&
  shouldThrowError(observer.options.throwOnError, [result.error])
) {
  throw result.error
}

So a mutationFn that rejects with a falsy value leaves the mutation in the error state, with isError set to true, while the boundary never sees it and throwOnError is never consulted.

useBaseQuery is already correct here through getHasError in errorBoundaryUtils.ts, which gates on result.isError. #11309 is fixing the matching case in useQueries. This is the remaining one.

The fix

Gate on result.isError instead.

Test

packages/preact-query/src/__tests__/useMutation.test.tsx gets a case where the mutationFn rejects with '' and throwOnError: true is set, expecting the boundary fallback to render. It fails on main and passes with the change.

One note on why the test rejects with '' rather than undefined: Preact's own diff reads e.then on the thrown value in packages/preact/src/diff/index.js before handing it to _catchError, so throwing undefined or null throws inside Preact itself. That is a Preact limitation and not something this adapter can do anything about, so the test uses a falsy value Preact can actually carry to a boundary.

Full @tanstack/preact-query suite passes (385 tests).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed useMutation so errors with falsy values are correctly propagated to the error boundary when throwOnError is enabled.
  • Tests
    • Added coverage verifying that falsy rejected values reach the error boundary as expected.

…or boundary

useMutation gated the error boundary throw on `result.error` being truthy, so a
mutationFn that rejects with a falsy value such as `Promise.reject('')` leaves
the mutation in the error state without the boundary ever seeing it.

Gate on `result.isError` instead, matching useBaseQuery's getHasError and the
same fix applied to useQueries in TanStack#11309.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MfJ49iHsRNpy4oibuXzrz
@coderabbitai

coderabbitai Bot commented Aug 27, 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: 979bf607-e4a3-42b9-94d0-2701f2acb0c6

📥 Commits

Reviewing files that changed from the base of the PR and between 714df67 and 6b913f2.

📒 Files selected for processing (3)
  • .changeset/spotty-hounds-clap.md
  • packages/preact-query/src/__tests__/useMutation.test.tsx
  • packages/preact-query/src/useMutation.ts

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


📝 Walkthrough

Walkthrough

useMutation now rethrows falsy rejected values when throwOnError is enabled. A regression test covers an empty-string rejection, and a patch changeset records the fix.

Changes

Mutation error boundary handling

Layer / File(s) Summary
Falsy error rethrow and regression coverage
packages/preact-query/src/useMutation.ts, packages/preact-query/src/__tests__/useMutation.test.tsx, .changeset/spotty-hounds-clap.md
The error boundary guard now checks result.isError instead of the truthiness of result.error. The test verifies that an empty-string rejection renders the error boundary fallback. The changeset records a patch release for @tanstack/preact-query.

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

Merge Risk: ⚪ Minimal · up to 6b913

This localized fix ensures falsy mutation errors reach the configured error boundary, with a regression test covering the behavior; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: sukvvon

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 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
Title check ✅ Passed The title clearly and concisely identifies the primary change: propagating falsy errors from Preact Query's useMutation to the error boundary.
Description check ✅ Passed The description clearly explains the bug, the implementation fix, the regression test, the Preact limitation, and the test result. It does not reproduce the template headings or checklist, but it incl…
Linked Issues 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.
Full details: Description check

Explanation

The description clearly explains the bug, the implementation fix, the regression test, the Preact limitation, and the test result. It does not reproduce the template headings or checklist, but it includes the core required change and validation information.

Full details: Docstring Coverage

Explanation

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

  • 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.

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.

2 participants