Course contentsShow
← React
Lesson 1668 of 2,39640. Server-Side RenderingFree lesson

The onShellReady and onAllReady Callbacks

Control when to send the initial response using onShellReady for fast FCP or onAllReady for complete content delivery.

The onShellReady and onAllReady Callbacks

You'll learn: How to control when your server sends the initial HTML response to the browser, choosing between fast First Contentful Paint or complete content delivery.

When you use renderToPipeableStream, you need to decide when to actually start sending HTML to the client. React gives you two callback options: onShellReady and onAllReady.

onShellReady: Fast First Paint

onShellReady fires as soon as React has rendered everything outside your Suspense boundaries—what we call the "shell" of your app. This includes your layout, navigation, and any components that loaded synchronously. Suspense boundaries that haven't resolved yet are left as placeholders.

When to use it: For user-facing pages where you want the fastest possible First Contentful Paint (FCP). Users see your app structure immediately, and Suspense boundaries stream in afterward.

const { pipe } = renderToPipeableStream(<App />, {
  onShellReady() {
    response.statusCode = 200;
    response.setHeader('Content-Type', 'text/html');
    pipe(response); // Start sending HTML now!
  }
});

onAllReady: Complete Content Delivery

onAllReady fires only after everything has rendered, including all resolved Suspense boundaries. You get a complete HTML document.

When to use it: For crawlers, static generation, or when you need the full content in one response (like generating PDFs or emails).

const { pipe } = renderToPipeableStream(<App />, {
  onAllReady() {
    pipe(response); // Send complete HTML
  }
});

The Decision

Think of it like a restaurant: onShellReady serves the appetizer immediately while the main course cooks, keeping customers happy. onAllReady waits until the entire meal is ready before bringing anything out.

Key Takeaway: Use onShellReady for fast user-facing pages with streaming, and onAllReady for crawlers or when you need complete HTML upfront.