fix(preact-query): propagate falsy errors from useMutation to the error boundary - #11312
fix(preact-query): propagate falsy errors from useMutation to the error boundary#11312yogesh968 wants to merge 1 commit into
Conversation
…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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
ChangesMutation error boundary handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to 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: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation 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 CoverageExplanation 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.)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Same bug as #11311, in the Preact adapter.
useMutationgates the error boundary throw on the error value itself being truthy:So a
mutationFnthat rejects with a falsy value leaves the mutation in the error state, withisErrorset totrue, while the boundary never sees it andthrowOnErroris never consulted.useBaseQueryis already correct here throughgetHasErrorinerrorBoundaryUtils.ts, which gates onresult.isError. #11309 is fixing the matching case inuseQueries. This is the remaining one.The fix
Gate on
result.isErrorinstead.Test
packages/preact-query/src/__tests__/useMutation.test.tsxgets a case where themutationFnrejects with''andthrowOnError: trueis set, expecting the boundary fallback to render. It fails onmainand passes with the change.One note on why the test rejects with
''rather thanundefined: Preact's own diff readse.thenon the thrown value inpackages/preact/src/diff/index.jsbefore handing it to_catchError, so throwingundefinedornullthrows 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-querysuite passes (385 tests).Summary by CodeRabbit
useMutationso errors with falsy values are correctly propagated to the error boundary whenthrowOnErroris enabled.