الانتقال إلى المحتوى
FrontendReact· 7 دقائق للقراءة

'use server' Doesn't Mark Server Components: What Server Functions Really Are

Server Components need no directive. 'use server' turns async functions into endpoints the browser can call, with arguments it controls.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
  • React 19
محتويات المقال

A developer is moving an orders page to . They've seen 'use client' at the top of interactive files, so to make the page run on the server they add 'use server' to the top of OrdersPage.tsx. The file also exports cancelOrder, a small helper the page hands to its order list. The diff looks harmless and gets approved. A later security review flags it: the directive turned every export into a function the browser can call, including the one that deletes whatever order id it receives.

The common misconception

The belief: 'use server' is how you mark a Server Component, the mirror image of 'use client'. Put it at the top of a file and everything in it stays on the server.

The symmetry is hard to resist. Both directives are strings at the top of a file, both say where code runs, and the React docs place them side by side. React's own Server Components page calls this "a common misunderstanding", which tells you how many people have made it. The half that's true: 'use server' does draw a line between server and client code. It's just a different line, drawn around functions the client may call, not around components the server renders.

What actually happens

Server Components have no directive

React's reference states it directly: "there is no directive for Server Components." In an app built on them, everything is a Server Component unless it's defined in, or imported through, a module marked 'use client'. So making a page a Server Component takes no code at all. You only ever mark the other side: the point where client code starts. The page in the opening was a Server Component before anyone touched it; the directive changed only what the browser is allowed to call.

'use server' marks functions the client can call

'use server' goes at the top of an async function's body, or at the top of a file. Either way it creates . The framework passes the client a reference instead of the code, and when client code calls that reference, React sends a network request with a serialized copy of the arguments, runs the function on the server and sends back the serialized result. That's why the directive works only on async functions, and why arguments are limited to serializable values like strings, plain objects and FormData, never JSX or event objects.

At the top of a file, the directive marks every export as a Server Function that "can be used anywhere, including imported in client code". Here's the page from the opening, and the version that says what it means:

TSX OrdersPage.tsx
"use server"; // meant: "this page is a Server Component"export default async function OrdersPage() {  const user = await requireUser();  const orders = await findOrders(user.id);  return <OrderList orders={orders} onCancel={cancelOrder} />;}// Now a Server Function too: any client, any orderIdexport async function cancelOrder(orderId: string) {  await deleteOrder(orderId);}

On the left, both exports, the page itself and cancelOrder, are now Server Functions. In the right-hand version the page needs nothing to be a Server Component, and only cancelOrder is exposed. It also doesn't trust its caller: it looks up the current user again on the server and deletes the order only if that user owns it.

Calling one from the client

To the Client Component, the prop is just an async function. Passed to <form action>, the pattern from the form actions article in this path, React calls it in a for you, and with useActionState it even replays submissions made before hydration finishes. Anywhere else, the docs say to call it in a Transition yourself, which gives you a pending state, optimistic updates and error handling:

TSX CancelButton.tsx
"use client";import { useTransition } from "react";type Props = { orderId: string; onCancel: (id: string) => Promise<void> };export function CancelButton({ orderId, onCancel }: Props) {  const [isPending, startTransition] = useTransition();  return (    <button      disabled={isPending}      onClick={() => startTransition(() => onCancel(orderId))}    >      {isPending ? "Cancelling…" : "Cancel"}    </button>  );}
MythReality
'use server' makes a component a Server ComponentThere's no directive for Server Components; they're the default
'use server' keeps a file's code private on the serverIt exposes every export as a function the client can call
Only my own UI calls my Server FunctionsArguments are fully client-controlled, so validate and authorize
Any function can be a Server FunctionOnly async functions, with serializable arguments and results
Server Functions are a handy way to load dataThey're meant for mutations; read data in Server Components

How to apply it in your project

  1. List what your 'use server' files exportSearch for 'use server' at the top of files. Every export is a callable endpoint; move anything that shouldn't be into a plain module.
  2. Remove the directive from componentsPages and components meant to be Server Components need no directive. If one has 'use server' at the top, delete it.
  3. Guard every Server FunctionAt the start of each one, validate the arguments and re-check on the server that the current user may do this.
  4. Move reads out, keep writes inLoad data in Server Components, and call Server Functions for mutations through <form action>, useActionState or startTransition.

Key takeaways

  • There's no directive for Server Components: they're the default, and 'use client' marks where client code starts.
  • 'use server' creates Server Functions: async functions the client calls over the network with serialized arguments.
  • At the top of a file it exposes every export, so treat each as a public endpoint: validate and authorize.
  • Use Server Functions for mutations, called from forms or Transitions, and read data in Server Components.

📚 المصادر

  1. Server Components — React Reference
  2. 'use server' — React Server Components Reference
  3. Server Functions — React Reference
  4. Directives — React Server Components Reference

التعليقات (0)