Summary
This is a follow-up to #27563.
The SSR Flight client's encodeFormAction callback fully replaces React's default form action encoding. A framework cannot call the default encoder and change only one field.
A common use case is changing the form action URL while keeping the default encoding, so decodeAction still works. For example, a framework may add a query parameter that identifies a no-JS action request without reading the request body.
Today, frameworks must copy React's encoding behavior using public APIs. This includes serializing the arguments, renaming fields, generating prefixes, caching results, and handling suspension. The callback also does not receive identifierPrefix or a stable identity for unbound references.
This logic now exists in two implementations:
- waku: https://github.com/wakujs/waku/pull/2191
@vitejs/plugin-rsc: https://github.com/vitejs/vite-plugin-react/pull/1280
Proposal
Pass a bound default encoder to the callback:
encodeFormAction?: (
id: string,
args: Promise<unknown[]>,
encodeDefault: () => ReactCustomFormAction,
) => ReactCustomFormAction;
A framework could then write:
const encodeFormAction = (id, args, encodeDefault) => ({
...encodeDefault(),
action: currentUrl + '?my-marker=1',
});