Skip to main content
BERTA MATULIAUSKIENE@Berta.codes
  • AI ADOPTION
  • PERSONAL BRAND
  • BLOG
  • ABOUT
  • RESOURCES
    • SETUP
    • AI PROMPTS
    • APPS
  • AI ADOPTION
  • PERSONAL BRAND
  • BLOG
  • ABOUT
  • RESOURCES
    • SETUP
    • AI PROMPTS
    • APPS
Appearance
Find Me Online

Find me online

Explore

  • About Berta
  • Articles
  • Newsletter

Resources

  • AI prompt library
  • My apps

Consulting

  • Practical AI adoption
  • Personal brand review
  • hello@bertacodes.com

STAY CURIOUS

PrivacyRSS feed

© 2026 BERTA CODES

Back to blog
Next.jsReactServer Components

Server Components vs Client Components in Next.js

Key differences between Server and Client Components across Next.js versions 13, 14, and 15.

March 14, 2025
Updated October 23, 2026
Berta Matuliauskiene
10 min read
Server Components vs Client Components in Next.js

Server or client? In the Next.js App Router, I start with what a component needs to do. Reading data and rendering content can usually stay on the server. State, event handlers, and browser APIs need a client boundary.

Version scope: this article covers the App Router model introduced in Next.js 13, with examples written for Next.js 15. It is not a guide to the latest release. Use the current documentation for a new project and check the documentation for your installed version.

Correction, October 23, 2026: removed unsupported performance percentages and corrected Client Component prerendering, async params, and the Form example. The examples below illustrate the component boundary; they are not a complete production application.

Understanding the Component Model Evolution#

Layouts and pages in the App Router are Server Components by default. Add 'use client' when a component needs client features, such as useState or an onClick handler.

The important distinction is which code needs to run in the browser, not whether the visitor receives HTML.

Rendering Location#

Server Components run on the server, either during a build or when handling a request, depending on the route. Their component code is not shipped to the browser. The server produces a React Server Component payload, which Next.js uses together with Client Components to prepare the initial HTML.

Client Components are also prerendered on the server for the initial full-page load. The browser then uses their JavaScript to hydrate them: connecting the displayed HTML to state and event handlers. Subsequent navigation can render Client Components in the browser without fetching a new full HTML document.

So 'use client' does not mean “never runs on the server.” Reading window or localStorage during rendering can still fail. Put browser-only work in an effect or an event handler.

The Next.js 15 component guide explains the initial render and hydration steps.

Data Fetching Patterns#

A Server Component can be an async function and read data before returning its UI. For independent requests, start both before awaiting them with Promise.all. If one request needs the result of another, that dependency still makes them sequential.

An awaited request can delay the part of the page that depends on it. Use loading.js or a Suspense boundary to provide a fallback and stream ready content. Being a Server Component does not make every fetch non-blocking.

A Client Component can receive already-fetched data as props. It does not need its own useEffect fetch just because it is interactive. Client-side fetching is useful when data must change after interaction or refresh in the browser; a data library can help manage caching, errors, and request lifecycles.

See the Next.js 15 data-fetching guide for fetching and streaming patterns.

Interactivity and Event Handling#

Use a Client Component for:

  • State and effects, such as useState and useEffect.
  • Event handlers, such as onClick and onChange.
  • Browser APIs used after mounting or in response to an event.
  • Libraries or custom hooks that depend on these features.

Server Components cannot use state or effect hooks or attach browser event handlers. That does not mean every React hook is forbidden: the restriction depends on the API. Check the relevant React documentation rather than applying a rule based on the word “hook.”

Here is a small interactive component:

// app/counter.js
'use client';

import { useState } from 'react';

export default function Counter() {
  const [count, setCount] = useState(0);

  return (
    <button onClick={() => setCount(current => current + 1)}>
      Count: {count}
    </button>
  );
}

No compiler setting is required for this example. React Compiler support in Next.js 15 was an opt-in experimental feature, not a performance benefit automatically applied to every Client Component.

Bundle Size Impact#

The code of a Server Component stays on the server. That can keep data-access code and server-only dependencies out of the browser bundle.

Client Components and their client-side imports need browser JavaScript. A 'use client' boundary also includes its imported dependencies; you do not need the directive in every file below that boundary. Keep it near the parts that need interaction instead of marking a whole page client-side by habit.

This is not a guarantee of a smaller or faster page in every situation. HTML, the RSC payload, images, fonts, and any nested Client Components still need to reach the user. Measure the route that matters to you.

React's use client reference describes the module boundary and supported serializable values.

Component Composition Patterns#

A Server Component can render a Client Component and pass data to it. The values crossing the boundary must be serializable by React; ordinary objects with strings and numbers are a simple starting point.

The following example keeps product information on the server and moves the quantity selector into a small Client Component. The fixed product is illustrative; replace it with your own validated data source when needed.

// app/products/[id]/page.js — Next.js 15
import { notFound } from 'next/navigation';
import QuantitySelector from './quantity-selector';

export default async function ProductPage({ params }) {
  const { id } = await params;
  const product = { id: 'notebook', name: 'Notebook', price: 12 };

  if (id !== product.id) {
    notFound();
  }

  return (
    <section>
      <h1>{product.name}</h1>
      <p>€{product.price.toFixed(2)}</p>
      <QuantitySelector productName={product.name} />
    </section>
  );
}
// app/products/[id]/quantity-selector.js
'use client';

import { useState } from 'react';

export default function QuantitySelector({ productName }) {
  const [quantity, setQuantity] = useState(1);

  return (
    <div>
      <p aria-live="polite">
        {productName}: {quantity}
      </p>
      <button onClick={() => setQuantity(current => current + 1)}>
        Increase quantity
      </button>
    </div>
  );
}

A Server Component can also pass server-rendered content as children to a Client Component, for example inside an interactive modal. Keep the Server Component import in the server parent; importing it directly from a client module makes it part of that client dependency tree instead.

For a static export, the product route also needs generateStaticParams for the known product IDs. A request-time data source or a server mutation needs a suitable server deployment; a static export does not create a running backend.

Form Handling and Server Actions#

Server Actions let forms call server-side functions. In a Server Component, a native form with a Server Function passed to its action prop can support progressive enhancement. Validation, authentication, and authorization still belong in the server action where required; the framework does not supply your business rules.

Next.js 15 also introduced next/form. With a string action, it performs GET-style navigation with the form fields in the URL and provides navigation enhancements. With a function action, it executes the action like a React form.

It does not provide a ({ pending, data }) => ... render-prop child. For an action's pending/result state, use the documented React form hooks, such as useActionState or useFormStatus, in an appropriate Client Component.

A small search example using a string action:

// app/search-form.js
import Form from 'next/form';

export default function SearchForm() {
  return (
    <Form action="/search">
      <label htmlFor="query">Search products</label>
      <input id="query" name="query" type="search" required />
      <button type="submit">Search</button>
    </Form>
  );
}
// app/search/page.js — Next.js 15, requires a server deployment
export default async function SearchPage({ searchParams }) {
  const { query } = await searchParams;
  const search = typeof query === 'string' ? query : '';

  return <p>You searched for: {search}</p>;
}

This displays the query; it does not implement a product search or save data. See the Next.js 15 Form reference and forms guide for action state and validation examples.

Error Handling#

Use an error.js boundary for unexpected rendering errors in its child content. Errors in the same segment's layout need a parent boundary; errors in the root layout need global-error.js. The boundary itself is a Client Component, even when the error originated in server-rendered content.

Handle expected failures, such as invalid form input, as part of the UI. Event-handler errors are not automatically caught by rendering error boundaries; handle those in the event or action flow.

If you redirect after a successful Server Action, call redirect() outside a try/catch that would swallow it: Next.js implements the redirect by throwing. Read the error-handling guide and redirect reference for the relevant boundaries.

SEO and Metadata#

Client Components are not inherently bad for SEO. Their prerendered content can be included in the initial HTML. Content fetched only after mounting is a separate case: the initial response may contain a loading state rather than the final content.

Keep important page information available in the initial response where practical. Also use meaningful headings, links, and metadata. Choosing a component type alone does not guarantee indexing or rankings.

Next.js metadata exports belong in Server Components. In Next.js 15, await params when using it in generateMetadata, just as in a page component:

// Add to app/products/[id]/page.js
export async function generateMetadata({ params }) {
  const { id } = await params;

  return {
    title: id === 'notebook' ? 'Notebook | My Store' : 'Product | My Store',
    description: 'Product details from My Store.',
  };
}

This example uses the fixed product above. In a real application, generate the title and description from your validated product data. The generateMetadata reference documents the supported fields and async props.

Version Differences to Check#

The component boundary is broadly the same across the App Router versions covered here. Some surrounding APIs changed:

  • Next.js 13 introduced the App Router model; it became stable in 13.4. Server Actions were experimental.
  • Next.js 14 made Server Actions stable. Partial Prerendering was experimental; ordinary streaming was not a new feature exclusive to this version.
  • Next.js 15 changed request APIs such as params, searchParams, cookies(), and headers() to async APIs. It also changed caching defaults for fetches, GET Route Handlers, and client navigation. That does not mean every part of the Router Cache is disabled: shared layouts and back/forward navigation still have caching behavior.

Read the Next.js 13.4 announcement, Next.js 14 announcement, and Next.js 15 upgrade guide when maintaining an older project. None of these version changes establishes a universal percentage improvement for your application.

TypeScript Configuration Support#

Next.js 15 supports next.config.ts. That is a project-configuration option, not a reason to choose Server or Client Components.

// next.config.ts
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
  reactStrictMode: true,
};

export default nextConfig;

Use the versioned configuration reference for additional settings rather than copying unrelated experimental options.

When to Use Each Component Type#

Start with a Server Component for data access, server-only dependencies, and content that does not need browser state. Keep secrets out of the props and output sent to the browser; server execution alone does not prevent you from accidentally exposing data.

Add a Client Component where someone needs to interact: a counter, form feedback, modal, filter, or a control using browser APIs. Pass the data it needs across a small, explicit boundary.

For me, the useful question is: “Which part actually needs browser JavaScript?” Answer that first, then measure the result. Most pages need a combination of server-rendered content and a few interactive pieces.

Share this post

Previous Article

Tailwind CSS Class Organization and Lint...

Next Article

Understanding GraphQL in 2025: A Compreh...

You might also like

The Complete Guide to Next.js Project Setup in 2025

The Complete Guide to Next.js Project Setup in 2025

March 7, 2025

10 Key Differences Between React.js and Next.js in 2025

10 Key Differences Between React.js and Next.js in 2025

March 2, 2025

GraphQL and Next.js: Filtering, Searching, and Sorting

GraphQL and Next.js: Filtering, Searching, and Sorting

March 18, 2025

Table of Contents

  • Understanding the Component Model Evolution
  • Component Composition Patterns
  • Form Handling and Server Actions
  • Error Handling
  • SEO and Metadata
  • Version Differences to Check
  • TypeScript Configuration Support
  • When to Use Each Component Type

Recent Posts

  • How to Start Using AI at Work: Choose One Task You Can Check
    October 23, 2026
  • A Personal Brand Profile Review: What Should a Stranger Understand?
    October 23, 2026
  • Harness Engineering: Building Our Own Tools While Teaching AI How We Work
    October 21, 2026
  • AI Automation: The Biggest Challenge Is Not How, but What, Where, When, and How Much
    October 17, 2026
  • When Human in the Loop Becomes Theatre
    October 8, 2026