Question presented to candidate:
"What does the "use server" directive actually do to a function?"
What a strong answer should cover:
- It marks a function as callable from the client but executed on the server. The bundler replaces the function body in the client bundle with a reference, and calling it performs a network request.
- So it is RPC with a function-call syntax β the ergonomics of calling a function, the semantics of a POST.
- The body never ships. That is the security property: a Server Action can read secrets and query the database because its code does not exist in the browser.
- It is the inverse of
"use client". One marks code that ships; the other marks code that never does. - Arguments and return values must be serialisable, because they are crossing a network.
- Every Server Action is a public HTTP endpoint. Anyone can call it with any arguments. It must authenticate and validate exactly like an API route β the directive is not authorisation.
- On the client it plugs into the same machinery as any Action: pass it to
<form action>, wrap it withuseActionState, read status withuseFormStatus. - With a form it works before hydration, because the form can post to the endpoint natively.
Clarifying questions expected:
- "Who is allowed to call this, and is that checked inside the action?" β the security question, and the important one.
- "Is this called from a form or from an event handler?" β that decides progressive enhancement.
Code / implementation expected: Optional. The security point is what distinguishes a strong answer.