The onShellReady and onAllReady Callbacks
You'll learn when to start sending HTML to the browser: immediately after the initial shell or after everything finishes rendering.
The Two Moments That Matter
When you call renderToPipeableStream, React gives you two critical callbacks that determine when to start sending HTML:
onShellReady fires when the initial HTML "shell" is ready — the basic structure of your page, excluding content inside <Suspense> boundaries that's still loading. This fires quickly.
onAllReady fires when everything has rendered, including all suspended content. This can take much longer.
Think of It Like a Restaurant
Imagine a restaurant preparing a multi-course meal:
- onShellReady: The table is set, the ambiance is ready, guests can sit down. The appetizers are still cooking, but the experience can begin.
- onAllReady: Every single dish is plated and ready. Nothing's in the kitchen anymore.
Choosing Your Strategy
renderToPipeableStream(element, {
onShellReady() {
// Send HTML immediately - users see something fast
res.setHeader('Content-Type', 'text/html');
pipe(res);
},
onAllReady() {
// Or wait here if you need complete HTML
// (SEO crawlers, static generation)
}
});
For interactive user-facing pages: Use onShellReady to start streaming immediately. Users see the page structure instantly while remaining content loads.
For crawlers or static HTML: Use onAllReady to ensure the complete page is rendered before sending anything.
Key Takeaway: onShellReady starts streaming as soon as the page skeleton is ready (fast user experience), while onAllReady waits for complete rendering (complete HTML delivery).