--- title: The Server and Client Boundary nav_title: Server and Client Boundary description: Learn where Server and Client Components run in the App Router and how the boundary between them works. related: title: Next Steps description: Learn how to apply this model and where the boundary is defined. links: - app/getting-started/server-and-client-components - app/api-reference/directives/use-client - app/getting-started/fetching-data - app/guides/rendering-philosophy --- React Server Components (RSC) split a component tree between server and client module graphs. This boundary determines where component code runs and whether that code ships to the browser. RSC keeps Server Components exclusively on the server and retains Client Components for interactive UI. Both compose in a single tree, which the server renders into the [RSC Payload](/docs/app/glossary#rsc-payload), a serialized description of the UI that carries references to the Client Components inside it. Before RSC, React components followed what RSC now calls the Client Component model. React could render these components to HTML on the server, but the same code also shipped to the browser to [hydrate](https://react.dev/reference/react-dom/client/hydrateRoot#hydrating-server-rendered-html) that HTML. Hydration made the initial HTML interactive and required the component to produce matching output on the server and in the browser. Apps rendered entirely on the client could instead begin with an empty shell and mount the component tree in the browser. ```txt Server Component ├─ Server Component └─ Client Component └─ Client Component ``` Each component's module belongs to the server [module graph](/docs/app/glossary#module-graph), the client module graph, or both. Next.js compiles a module used by both graphs separately for each environment. During rendering, the server graph produces references to Client Components and serializes the props passed to them. The client graph does not import the server graph. The client graph receives the references and serialized props through the RSC Payload. ## Rendering environments The component names suggest a clean split between server and browser, but rendering happens in both places. On the server, the Server Component tree produces the RSC Payload. Next.js uses the payload and Client Components to render HTML at build time or while handling a request. When deciding where a component runs, consider both its server render and whether its code runs in the browser: | | On the server | In the browser | | -------------------- | ------------- | -------------- | | **Server Component** | Yes | No | | **Client Component** | Yes | Yes | The word "Client" indicates that a Client Component also runs in the browser, alongside its server render. On a direct visit, the following Client Component renders on the server and again in the browser during hydration. Its log appears in the terminal and the browser console. On a client-side navigation, the server sends the RSC Payload, and the component renders in the browser without server-rendered HTML. ```tsx filename="app/hello.tsx" switcher 'use client' export default function Hello() { console.log('Hello rendered') // on a direct visit: server, then browser return
Hello
} ``` ```jsx filename="app/hello.js" switcher 'use client' export default function Hello() { console.log('Hello rendered') // on a direct visit: server, then browser returnHello
} ``` Rendering a Client Component on the server produces HTML, but the component remains a Client Component. Rendering Client Components to HTML predates RSC. Depending on the route, Next.js can generate or regenerate HTML: - At build time with [Static Site Generation (SSG)](/docs/app/glossary#prerendering). - After the build with [Incremental Static Regeneration (ISR)](/docs/app/glossary#incremental-static-regeneration-isr). - For each request with server-side rendering (SSR). RSC is a separate process that keeps Server Component code on the server and emits the RSC Payload instead of shipping that code. "Server-rendered" describes how Next.js produced the HTML. "Server Component" describes where the component code runs and whether that code ships to the browser. > **Server Components and SEO** > > A crawler that reads only HTML sees the first response and runs none of your JavaScript. Both Server and Client Components contribute HTML to that response. > > SEO depends on whether the server render reaches the content. Content gated behind user interaction or an event does not appear in the HTML available to a crawler that does not run JavaScript. See [Rendering Philosophy](/docs/app/guides/rendering-philosophy) for details about when a component renders, whether at build time or per request, statically or dynamically. ## How data enters the tree Before RSC, Next.js applications typically gathered server data with functions such as `getStaticProps` or `getServerSideProps`, then passed it to the component tree as props. Data fetching happened before the tree rendered. The tree received data instead of fetching it during render. ```txt Data ↓ Loader or API ↓ Props ↓ Component tree ``` Because a Server Component runs only on the server, it can access resources such as a database, the filesystem, an internal service, or a secret. The component reads these resources during its own render, without an API route that exposes the data to the client first. ```tsx filename="app/page.tsx" switcher import { PostList } from '@/app/ui/post-list' import { getPosts } from '@/lib/data' export default async function Page() { const posts = await getPosts() // runs on the server, during render return