You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: prevent useActionState state becoming undefined when redirect() is called
Fixes issue #589 where useActionState receives undefined state when a Server Action
calls redirect() from next/navigation.
Root Cause:
When a server action used with useActionState calls redirect(), the browser entry
was returning undefined after triggering navigation. React's useActionState hook
uses the return value as the new state, causing it to become undefined and crash
with TypeError on the next render.
Solution:
Trigger navigation without awaiting (using void operator), allowing the navigation
to proceed in the background. The navigation will re-render the page at the new URL
before the state update causes issues.
Changes:
- packages/vinext/src/server/app-browser-entry.ts: Use void operator for fire-and-forget navigation
- tests/fixtures/app-basic/app/actions/actions.ts: Add redirectWithActionState test action
- tests/fixtures/app-basic/app/action-state-redirect/page.tsx: Add test page
- tests/e2e/app-router/server-actions.spec.ts: Add E2E test for issue #589
- tests/repro-589.spec.ts: Update reproduction test
Signed-off-by: Md Yunus <admin@yunuscollege.eu.org>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
0 commit comments