Next.js

Streaming, Suspense, and Hydration in Next.js Development

Blazity team
23 Jun 2025
2 min. read

Streaming, Suspense, and Hydration in Next.js Development

This article explores streaming, suspense, and hydration in Next.js development, detailing their concepts, benefits, and implementation to optimize web application performance and interactivity.

What Is Streaming, Suspense, and Hydration in Next.js?

What is streaming?

Streaming is a technique that allows you to break down the rendering process into smaller, manageable chunks. Instead of waiting for all the data to load before showing the full page, streaming lets your app render and send parts of the page as soon as they're ready.

Why does streaming matter?

  • Enhancing perceived performance by displaying critical content first.
  • Reducing user frustration by minimizing blank or loading screens.
  • Optimizing server efficiency by handling data transfer in chunks.
  • Improving SEO and conversions through faster load times.

What is hydration?

Hydration refers to the process where a server-rendered or statically generated page becomes fully interactive on the client side. When using SSR, the server generates and sends the initial HTML. Hydration occurs when the client-side JavaScript framework loads and reuses the pre-rendered HTML instead of generating it from scratch.

Important: The content rendered on the server and client must be identical. If not, a hydration mismatch error is thrown. Common causes:

  1. Usage of typeof window conditional rendering in JSX.
  2. Local date formatting differences.
  3. Any random values like Math.random().

What is the problem with hydration?

  • Performance Overhead: The browser must download, parse, and execute JavaScript to rehydrate the page.
  • JavaScript Bloat: Large applications accumulate excessive JavaScript.
  • Delayed Interactivity: Content appears instantly but interactions aren't available until hydration completes.

Implementation

Progressive/Selective Hydration & Suspense

Selective Hydration breaks hydration into smaller units called Suspense boundaries. By wrapping individual components in <Suspense>, React can prioritize the hydration of these smaller chunks based on user interaction.

Key Features:

  • Streaming HTML: HTML is streamed progressively as it's rendered on the server.
  • Prioritization of Hydration: Based on user interactions and rendering order.
  • Reduced Blocking: React handles boundaries in smaller chunks.

Code Example

import { Suspense } from 'react';
import Comments from './comments';
import Sidebar from './sidebar';
import Spinner from './spinner';

export const PageContent = () => {
  return (
    <main>
      <h1>Welcome to the Blog</h1>
      <Suspense fallback={<Spinner />}>
        <Sidebar />
      </Suspense>
      <article>
        <h2>Main Article</h2>
        <p>Content of the main article...</p>
      </article>
      <Suspense fallback={<Spinner />}>
        <Comments />
      </Suspense>
    </main>
  );
};

Keypoints

  1. Hydration adds performance overhead but fast initial pages still need to be served from the server.
  2. Progressive and Selective Hydration improve performance by not hydrating the entire page simultaneously.
  3. React's Suspense feature allows breaking hydration into smaller chunks, enabling selective loading.
  4. Next.js App Directory streams HTML progressively using Suspense boundaries.

Subscribe to our newsletter

Get Next.js tips, case studies, and frontend insights delivered to your inbox.

By clicking Sign Up you request to receive newsletters from us in accordance with Website Terms. The Controller of your personal data is Blazity Sp. z o.o. with its registered office at Warsaw, Poland, who processes your personal data for marketing purposes. You have the right to data access, rectification, erasure, restriction and portability, object to processing and to lodge a complaint with a supervisory authority. For detailed information, please refer to the Privacy Policy.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.