Question presented to candidate: "Explain what happens, end to end, when a user clicks a button that calls a Server Action. What travels over the network, and what does the action return?"
What a strong answer should cover:
- A Server Action (React Server Function) is an async function marked with 'use server'; it runs only on the server.
- The client never gets the code: it gets a reference (an action id) and calls it with a POST to the current route, carrying the arguments.
- The response is an RSC stream with the return value, and it can also carry a fresh render of the page when the action revalidates.
- Actions can be passed to forms (
action={fn}), called from event handlers, or used withuseActionState. - Every action is a public HTTP endpoint: authenticate and authorise inside it; the client dispatches actions one at a time.
Clarifying questions expected:
- "Is this a mutation or a read?" β actions are designed for mutations.
- "Who is allowed to trigger it?" β the check belongs inside the action.
Code / implementation expected: Yes β an actions file, a form and a button calling it.