Catalog My learning Blog
Frontend Developer Course: 100 Concepts in 100 Days · Phase 8 · Lesson 74 · 6 min read

React Server Components Explained

On this page
  1. Learning Objective
  2. Concept Explanation
  3. Worked Example: A Server Component Page with a Client Island and a Server Function
  4. Real-World Examples
  5. Review Questions & Answers

Learning Objective

Explain what React Server Components are, how they differ from server-side rendering, how the server and client component boundary works with the use client directive, what can cross that boundary as props, how server functions handle mutations, and the security rules that come with running components on the server.

Concept Explanation

React Server Components, RSC, are components that run only on the server, either at build time or per request. They can be async, read from databases, file systems and internal services directly, and use large libraries such as markdown parsers or syntax highlighters, and none of their code is sent to the browser. What the browser receives is their rendered output in a serialized format, the RSC payload, which React uses to build the UI and which interleaves with the client components that need interactivity.

Server components are different from server-side rendering. SSR runs ordinary components on the server to produce initial HTML and then ships all their code to the client to hydrate. With RSC, server components never hydrate because their code never reaches the client; only client components are hydrated. A page can be server-rendered with SSR and use server components at the same time, which is what frameworks such as Next.js App Router do: server components produce the payload, and SSR turns the initial payload plus client components into HTML for the first load.

The boundary is declared with the use client directive at the top of a file. That file and everything it imports become client code, bundled and hydrated. Components without the directive, in an RSC-enabled framework, are server components by default. Server components can render client components and pass them props, but those props must be serializable: strings, numbers, plain objects, arrays, dates, promises and JSX elements, but not functions or class instances, because they travel over the network. Client components cannot import server components, but they can receive server-rendered elements as children, which keeps large static parts of the tree on the server even inside interactive wrappers.

Mutations use server functions, marked with the use server directive. A server function can be passed to a client component or used as a form action; calling it from the client sends a request to the server, runs the function there and can trigger revalidation so the affected server components re-render with fresh data. This makes forms work even before JavaScript loads, in combination with React 19 form actions.

Security changes when components run on the server. Every server function is a public HTTP endpoint, whatever its name or where it is defined: it must authenticate the user, authorize the action and validate its arguments exactly like any API route. Data passed from server to client components is visible in the page, so never pass whole database records that contain secrets or private fields; pass only what the client needs, and keep server-only modules from being imported into client code, for example with the server-only package. The RSC protocol itself has had serious vulnerabilities, including a remote code execution flaw disclosed in December 2025, so frameworks and React packages must be kept up to date.

AspectServer componentClient component
RunsOn the server onlyServer for SSR, then in the browser
Code shipped to browserNoneYes, bundled and hydrated
Can be async and read data directlyYesNo, uses hooks and fetch
State, effects, event handlersNoYes
Declared byDefault in RSC frameworksuse client directive
Props it can receive from serverNot applicableSerializable values and JSX only
MutationsDefines server functionsCalls server functions

Worked Example: A Server Component Page with a Client Island and a Server Function

The page reads data directly on the server and sends only the fields the client needs. The like button is a client component that calls an authenticated, validated server function.

TypeScript
// app/posts/[id]/page.tsx: a server component (no directive)
import 'server-only';
import { db } from '@/lib/db';
import { renderMarkdown } from '@/lib/markdown';           // large library, never shipped to the browser
import { LikeButton } from './like-button';

export default async function PostPage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const post = await db.post.findUnique({ where: { id }, include: { author: true } });
  if (!post || !post.published) notFound();

  return (
    <article>
      <h1>{post.title}</h1>
      <p>By {post.author.displayName}</p>                      {/* not the author's email or password hash */}
      <div dangerouslySetInnerHTML={{ __html: await renderMarkdown(post.body) }} />   {/* sanitized in renderMarkdown */}
      <LikeButton postId={post.id} initialCount={post.likeCount} />   {/* only serializable, minimal props */}
    </article>
  );
}
TypeScript
// app/posts/[id]/like-button.tsx
'use client';
import { useOptimistic, useTransition } from 'react';
import { likePost } from './actions';

export function LikeButton({ postId, initialCount }: { postId: string; initialCount: number }) {
  const [count, addOptimistic] = useOptimistic(initialCount, (c, delta: number) => c + delta);
  const [pending, startTransition] = useTransition();
  return (
    <button disabled={pending} onClick={() => startTransition(async () => { addOptimistic(1); await likePost(postId); })}>
      Like ({count})
    </button>
  );
}
TypeScript
// app/posts/[id]/actions.ts
'use server';
import { z } from 'zod';
import { revalidatePath } from 'next/cache';

export async function likePost(rawId: unknown) {
  const postId = z.string().uuid().parse(rawId);            // a public endpoint: validate everything
  const user = await requireUser();                         // authenticate on every call
  await db.like.upsert({ where: { userId_postId: { userId: user.id, postId } }, create: { userId: user.id, postId }, update: {} });
  revalidatePath(`/posts/${postId}`);                       // server components re-render with the new count
}

The markdown library and database client add nothing to the browser bundle. The page passes the post id and a count to the client component rather than the whole post and author records, so private fields never appear in the payload.

Server components read the database and render markdown on the server, shipping no code. They pass only serializable, minimal props to client components, which hydrate and call server functions. Every server function is a public endpoint that must authenticate and validate.
Server components read the database and render markdown on the server, shipping no code. They pass only serializable, minimal props to client components, which hydrate and call server functions. Every server function is a public endpoint that must authenticate and validate.

Real-World Examples

  • Next.js 13 introduced the App Router in 2022 as the first major production implementation of React Server Components, and React 19, released in December 2024, made server components and server functions stable features of React itself.
  • In December 2025 the React team disclosed a critical remote code execution vulnerability in the React Server Components implementation, CVE-2025-55182, affecting frameworks such as Next.js that use the RSC protocol, and urged all users to upgrade immediately, a reminder that server-side component infrastructure is part of an application's attack surface.
Key TakeawaysReact Server Components run only on the server, can read data directly and ship no code to the browser at all. Client components, marked with use client, handle state and interaction and are hydrated. Pass only serializable, minimal props across the boundary, use server-rendered children inside client wrappers, and treat every server function as a public endpoint with authentication, authorization and validation. Keep the framework patched.

Review Questions & Answers

SSR runs components on the server to produce initial HTML and then ships all their code to the browser to hydrate. Server components run only on the server and their code is never sent to the browser; only their output is, and only client components are hydrated.

Serializable values: strings, numbers, booleans, plain objects and arrays, dates, promises and JSX elements, including server-rendered children. Functions and class instances cannot be passed, except server functions, which are sent as references to callable endpoints.

A server function is exposed as an HTTP endpoint that anyone can call with any arguments, regardless of which component uses it. Without checks inside the function, an attacker could perform actions as other users or send malformed data.

Pass only the specific fields a client component needs instead of whole records, keep sensitive logic in modules marked server-only so they cannot be imported into client code, and review the RSC payload, which is visible to anyone who loads the page.