fix(query-core): propagate AbortSignal reason in infiniteQueryBehavior fetchPage cancellation#10476
Conversation
…hPage (Closes TanStack#10475) Signed-off-by: Cocoon-Break <54054995+kuishou68@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Summary
Fixes #10475
Problem
In
infiniteQueryBehavior.ts, the internalfetchPagehelper function callsPromise.reject()without any argument when a query cancellation is detected via thecancelledflag (which is set by the AbortSignal abort event listener):When
query.cancel()→abortController.abort()is called, the abort signal fires and setscancelled = true. On the next iteration of the multi-page fetch loop,fetchPagerejects withundefinedinstead of the properAbortErrorthat is set ascontext.signal.reason.Fix
Propagate
context.signal.reasonas the rejection value, which is aDOMExceptionwith name"AbortError"whenAbortController.abort()is called without an explicit reason (per the AbortSignal spec):Impact
This fixes the following issues that occur when an infinite query is cancelled mid-pagination:
retryfunctions receivingundefinedinstead of anAbortErrorQueryCache.onErrorcallbacks receivingundefinedas the error argumentthrowOnErrorshowing"undefined"errorsTesting
The fix is minimal and targeted. The change ensures that when the AbortSignal fires during a multi-page infinite query fetch, the proper
DOMException{ name: "AbortError" }is propagated as the rejection reason, consistent with the Web AbortController specification.Summary by CodeRabbit