next-federation
Guides

Server Actions reference

Forms, the action identity, error codes, body limits and what does not work in a remote action.

Details behind Server Actions in islands.

Forms: no progressive enhancement

An island form is not submittable until the island hydrates.

  • <Form> from @next-federation/island renders a <fieldset disabled> on the server and enables it after hydration.
  • A plain <form action={action}>, or a formAction outside <Form>, warns NF-035.
  • A formAction button inside <Form> in the same component is not reported. One from another component cannot be checked, so the warning can be a false alarm.
  • Put a form that must work without JavaScript in the host.

Who the action runs as

Requests carry Authorization: Bearer <token>, never cookies. Without a token, getIdentity() is null.

  • Private islands use the token of the user they rendered for.
  • Public islands on a host with getIdentity fetch a token for the current user on each action. The cached page stays static.
  • On 401 NF-014, the island fetches a new token and resends once. It never retries NF-015, NF-016 or a 5xx.

Errors

CodeMeaning
NF-033The action threw. The caller sees "Minified React error #441" and the remote logs the cause (details).
NF-031The action id is unknown to the build, usually a page from one build calling another (details).
NF-032The request is malformed, or the body is too large (413).
NF-038The response is not a Server Action response, or the call timed out (details).
  • NF-032 is a 400 for a missing or malformed X-NF-Action header, an invalid island query parameter, a content type other than text/plain;charset=UTF-8 or multipart/form-data, or an undecodable body. A 413 means the arguments exceed the limit, for example a file in <Form> (limits).
  • NF-038 is a 5xx, a content type other than text/x-component, an empty body, or no answer within actions.timeoutMs (when set). A 5xx means the remote is down, restarting or timed out, or a proxy or CDN failed.
  • NF-031 is also a plain function export in a 'use server' file the bundler did not register.
  • The browser waits as long as the connection stays open. A proxy that cuts it surfaces as NF-038.
  • actions.timeoutMs covers the wait for the response, not a long streamed result.
  • Each call emits an island:action event (ok, status, code, ms, retried) on onEvent and the nf:island DOM event. It never includes arguments, results or tokens.

What does not work

  • redirect(), notFound(), cookies(), headers() and other next/* APIs. Return a value and let the island navigate.
  • Refreshing the island from the server. Only the calling island re-renders, from its own client state.

Body limits and NODE_ENV

LimitDefaultSet with
Build (413 with CORS)1 MiBactions.maxBodyBytes in the Vite options
nf-serve ceiling for /_nf/action8 MiBmaxActionBodyBytes of serveBuilds(). The CLI has no flag.

Keep the build's limit below the ceiling so callers see the build's answer.

Run rsc/index.js with NODE_ENV=production (nf-serve does). A rejected promise nested in a return value is redacted only by the production Flight server. The development one sends the message and stack to the browser. The build warns when NODE_ENV is not production.

Closures and replicas

Actions defined inside Server Components capture arguments encrypted with a key that @vitejs/plugin-rsc generates per build. Replicas built separately need the same key. Set defineEncryptionKey to a runtime secret.

On this page