← Back to Chapters

Streaming Server Rendering

? Streaming Server Rendering

⚛️ Introduction

Streaming Server Rendering (SSR) is a major React 18 improvement that makes server-side rendering faster and more efficient. Instead of waiting for the entire HTML page to be generated before sending it to the browser, React 18 streams content as it’s ready — improving First Paint and perceived performance.

Think of it as Netflix-style rendering — components start appearing as soon as possible, even while others are still loading.

? Traditional SSR vs Streaming SSR

  • Traditional SSR waits for the full HTML before responding.
  • Streaming SSR sends UI chunks as soon as they are ready.
  • Users see content earlier with streaming.
  • Best suited for large, data-driven applications.

⚙️ How Streaming SSR Works Conceptually

  1. Server starts rendering the React component tree.
  2. Completed components are streamed immediately.
  3. Browser displays partial UI while remaining content loads.
  4. Hydration occurs progressively per chunk.

This reduces Time to First Byte (TTFB) and improves Core Web Vitals.

? Interactive Simulation

Click buttons to feel the difference in loading strategies.

? Example (Node Server Concept)

? View Code Example
// server.js conceptual example using React 18 streaming SSR
import express from "express";
import { renderToPipeableStream } from "react-dom/server";
import App from "./App";

const app = express();

app.get("/", (req, res) => {
res.setHeader("Content-Type", "text/html");

const { pipe } = renderToPipeableStream(, {
onShellReady() {
// Start streaming HTML as soon as shell is ready
pipe(res);
},
onAllReady() {
// Called after entire component tree is rendered
console.log("All components rendered");
},
onError(err) {
// Handle rendering errors
console.error(err);
}
});
});

app.listen(3000);

renderToPipeableStream() allows HTML to stream immediately without waiting for heavy data dependencies.

? Key APIs and Concepts

  • renderToPipeableStream() — Streams HTML from Node.js.
  • onShellReady() — Fires when initial UI shell is ready.
  • onAllReady() — Executes after full render completion.
  • hydrateRoot() — Enables progressive client hydration.

? Benefits of Streaming SSR

  • ✅ Faster perceived page load
  • ✅ Improved SEO
  • ✅ Reduced hydration CPU spikes
  • ✅ Better user experience

⚠️ Limitations and Considerations

  • Requires Node.js or compatible runtime.
  • Some libraries may not fully support streaming.
  • Error handling is critical for partial HTML.
  • Frameworks like Next.js and Remix abstract complexity.

? Visual Streaming Flow (Concept)

Shell Components Hydration

This diagram represents how UI chunks stream sequentially to the browser.

? Tips

  • Use React 18+ with Node v16+.
  • Combine with Suspense for data loading.
  • Prefer frameworks for production setups.
  • Measure TTFB using Lighthouse.

? Try This

  1. Create a Node server with streaming enabled.
  2. Add a Suspense fallback.
  3. Compare traditional vs streaming SSR.
  4. Explore Next.js App Router.

Goal: Understand how Streaming SSR delivers progressive HTML and improves perceived performance.