Repository navigation
fix(toolkit): flag rejectedWithValue for falsy rejectWithValue payloads - #5395
Merged
markerikson merged 1 commit intoSep 19, 2026
Merged
markerikson merged 1 commit into
markerikson merged 1 commit into
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
@reduxjs/rtk-codemods
@rtk-query/codegen-openapi
@rtk-query/graphql-request-base-query
@reduxjs/toolkit
commit: |
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
rejectedWithValue for falsy rejectWithValue payloads
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.
Problem
rejectWithValue(0),rejectWithValue(''),rejectWithValue(false)andrejectWithValue(null)produce a rejected action that carries the payload but is flaggedrejectedWithValue: false.Three consumers then treat a deliberately handled rejection as an unhandled one:
unwrap()throws the generic{ message: 'Rejected' }rather than the value (createAsyncThunk.ts:784),isRejectedWithValue()does not match (matchers.ts:241), and RTK Query'squeryFulfilledrejects withisUnhandledError: true(queryLifecycle.ts:497-500).RTK Query reaches it without anything unusual:
buildThunks.ts:839passes whatever an endpoint'stransformErrorResponsereturns straight intorejectWithValue, so a transform that returns an empty string on an error response is enough.The type already treats this as a presence discriminant rather than a truthiness one -
createAsyncThunk.ts:407-412is a union on{ rejectedWithValue: false }vs{ rejectedWithValue: true } & GetRejectedMeta- and the docs sayrejectWithValuepasses "whatever value you give it".Fix
rejectedWithValue: payload !== undefined.One residual gap I left alone deliberately:
rejectWithValue(undefined)still flagsfalse, because therejectedprepare callback cannot distinguish a fourth argument ofundefinedfrom an absent one without an arity check, and that would change behaviour for anyone callingthunk.rejected(err, id, arg, undefined)directly. Happy to switch to the arity version if you would rather cover it.Tests
Four cases across the falsy values plus an
unwrapResultcase, added next to the existingrejectWithValuetests.packages/toolkitgoes 1067 to 1072 passing with no type errors; the suite has no pre-existing failures either way.Related to #4725, though I cannot confirm which falsy value that reporter's
transformErrorResponseproduced, so I am not claiming it as closed.