mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #589] useActionState receives undefined state when Server Action calls redirect() #129
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#129
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ayonli on GitHub (Mar 19, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/589
Bug Description
When a Server Action used with
useActionStatecallsredirect()(fromnext/navigation), thestatereturned byuseActionStatebecomesundefinedinstead of retaining the previous state. This causes aTypeErroron the next render if the component accesses any property onstate.Steps to Reproduce
redirect()on success:useActionStatein a Client Component:redirect(), and the component receivesundefinedas the new state, crashing with:Expected Behavior
When
redirect()is called inside a Server Action, the browser should navigate to the target URL. Thestatevalue fromuseActionStateshould either retain the previous state or remain in a defined shape — it should never becomeundefined.This is the standard Next.js behavior:
redirect()throws a special internal error that Next.js catches to perform the navigation, anduseActionStateis not involved in that process.Actual Behavior
statebecomesundefinedafterredirect()is called in the Server Action, causing aTypeErroron the next render.Workaround
Avoid calling
redirect()inside Server Actions used withuseActionState. Instead, return a success payload from the action and navigate client-side usingrouter.push()in auseEffect:Environment
@cloudflare/vite-plugin)