server-actions

Define and call React server actions for form submissions, mutations, and revalidation in Rango.

Updated Nov 7, 2025
One-click install
npx skills add https://github.com/rangojs/rango --skill server-actions-rangojs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: server-actions
Source: https://github.com/rangojs/rango/tree/main/packages/rangojs-router/skills/server-actions
Command: npx skills add https://github.com/rangojs/rango --skill server-actions-rangojs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Handling form submissions and data mutations in a React Server Components app requires wiring server functions, client hooks, validation, redirects, and cache revalidation together correctly. This Skill provides the complete patterns for defining and calling server actions in a Rango router application without guesswork. ## Core Features & Use Cases - Action Definition Patterns: Create file-level "use server" modules or inline actions inside server components, with guidance on serialization constraints and ID behavior. - Client Integration: Call actions via plain <form action={...}> for progressive enhancement, useActionState for validation state, useOptimistic for instant UI, useFormStatus for nested submit buttons, and useAction for imperative triggers. - Revalidation & Redirects: Control which route segments and loaders re-render after a mutation using revalidate() with ctx.isAction(), and perform same-origin-safe redirects with throw redirect(). - Use Case: Build a signup form with Zod validation that returns field-level errors via useActionState, preserves user input on failure, and redirects to a welcome page on success. ## Quick Start Ask the AI to create a server action with useActionState that validates a form with Zod and revalidates the owning route after submission.

Frequently Asked Questions about server-actions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a server action in React with "use server"?

Export an async function from a module with "use server" at the top, or declare an inline action inside a server component with the directive in the function body. File-level actions are preferred for reuse and support path-based revalidation matching.

How do I handle form validation errors with useActionState?

Return structured errors from the action as state instead of throwing, using the (prevState, formData) signature. Re-render the form with defaultValue from state.values so user input survives validation failures, and display errors per field.

When should I use a server action versus a loader?

Use server actions for writes and mutations, and loaders for reads. Actions mutate state and trigger revalidation of matched route segments, while loaders fetch live data on navigation or on demand from the client.

Does route middleware protect server actions in Rango?

No, route-level middleware() does not wrap action execution since actions run before route middleware. Place authorization checks in global router.use() middleware or inside the action body itself.

Why is my redirect from a server action blocked?

redirect() is same-origin by default, so cross-origin targets are blocked and the user is sent to the app root. Pass { external: true } to intentionally redirect off-host, and note the target must still be an http(s) URL.

Can server actions work without JavaScript enabled?

Yes, <form action={serverAction}> submits as a normal HTTP POST when JavaScript is unavailable, the action runs server-side, and the page re-renders. Write actions that accept FormData directly rather than curried or client-wrapped functions.