fix: don't swallow createAsyncThunk aborts that happen before pending#5314
Open
chatman-media wants to merge 1 commit into
Open
fix: don't swallow createAsyncThunk aborts that happen before pending#5314chatman-media wants to merge 1 commit into
createAsyncThunk aborts that happen before pending#5314chatman-media wants to merge 1 commit into
Conversation
When a thunk's `AbortController` was aborted before the `pending` action was dispatched - either because an already-aborted external `signal` was passed, or because `abort()` was called while an async `condition` was still pending - the resulting error was reported as a `ConditionError` with the message "Aborted due to condition callback returning false." Because `meta.condition` was then `true`, the `rejected` action was skipped by default (unless `dispatchConditionRejection` was set), so the abort was silently swallowed and the error was mislabeled even though no `condition` callback ever returned `false`. This was inconsistent with aborting the same signal moments later (once the thunk is running), which correctly produces a `rejected` action with an `AbortError`, and it contradicted the documented "Canceling While Running" behavior. The condition-check now only throws a `ConditionError` when `condition` actually returns `false`. If the controller was aborted, it instead throws an `AbortError` carrying the real abort reason, so the abort is reported and dispatched consistently regardless of timing.
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 42e83ce:
|
createAsyncThunk aborts that happen before pending
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
If a thunk's
AbortControlleris aborted before thependingaction is dispatched, the abort is silently swallowed and the error is mislabeled as aConditionError.This happens in two cases:
signalis passed to the thunk action creator.abort()is called during an asynccondition(before it resolves).In both cases the thunk currently throws:
Because the error is named
ConditionError, the resultingrejectedaction hasmeta.condition === true, so it is skipped by default (unlessdispatchConditionRejection: trueis set). The net effect:conditioncallback ever returnedfalse.This is inconsistent with aborting the same signal a moment later, once the thunk is already running. That path correctly produces a
rejectedaction with anAbortErrorandmeta.aborted === true, and matches the documented “Canceling While Running” behavior:Reproduction
The fix
The condition check in
createAsyncThunkpreviously collapsed two distinct cases into one:It now distinguishes them:
conditionreturningfalse→ConditionError(unchanged — still skipped by default).AbortErrorcarrying the real abort reason, so therejectedaction is dispatched and the error is labeled correctly, consistent with aborting afterpending.Tests
rejectedaction with anAbortErrorinstead of being swallowed. This test fails onmaster(expected 'ConditionError' to be 'AbortError') and passes with the fix.aborting during an async condition…(wasasync condition with AbortController signal first) now asserts arejectedaction with anAbortError.handles already aborted external signalnow asserts'External signal was aborted'(matching the siblingaccepts external signaltest) instead of theConditionErrormessage.Full
packages/toolkittest suite passes (60 files, 1055 tests).Related to #3826 (the broader family of swallowed errors from
condition/forceRefetch); this addresses the abort facet specifically. The genuinecondition === falseskip behavior is unchanged.