Skip to main content
skill CX Codex

react-selective-hydration — Claude Code skill: what it does, install

Guides your coding agent in setting up selective hydration and streaming SSR in React 18+. It makes interactive parts responsive before the entire JavaScript bundle downloads.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add PatternsDev/skills --skill react-selective-hydration -a claude-code
Open on GitHub

What react-selective-hydration does

Standard React SSR with renderToString halts tree transmission until every server component resolves. The client then stays inert until all JavaScript downloads. This skill directs the agent to replace synchronous rendering with React 18 streaming architecture.

Under the hood, the skill provides specific rules for server renderers: renderToPipeableStream for Node and renderToReadableStream for Web Stream edge runtimes. It specifies placing data-heavy blocks inside Suspense boundaries so initial HTML streams without delay. Interactive sibling components hydrate right away.

The pattern requires React 18+ with hydrateRoot. Putting critical interactive components inside long-lived loading fallbacks breaks the user experience, defeating the purpose of selective hydration.

What it helps with

  • migrate from renderToString to streaming SSR with renderToPipeableStream or renderToReadableStream
  • isolate slow data-fetching components behind Suspense boundaries
  • hydrate critical interactive components before all page scripts finish downloading
  • configure hydrateRoot for phased client-side hydration in React 18+

Example prompts for the agent

  • Migrate our SSR setup from renderToString to renderToPipeableStream with selective hydration
  • Wrap the comments widget in Suspense so slow API requests do not block hydration elsewhere
  • Check entry.server.tsx and implement streaming SSR for our Node runtime

How to install react-selective-hydration

1Skills CLI (Vercel)

npx skills add PatternsDev/skills --skill react-selective-hydration -a claude-code

2Manually: put the files in place

~/.claude/skills/react-selective-hydration/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/react-selective-hydration/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about react-selective-hydration

How to install react-selective-hydration in Claude Code?

Run npx skills add PatternsDev/skills --skill react-selective-hydration -a claude-code in your terminal.

What does react-selective-hydration do?

The skill guides your AI assistant on configuring streaming SSR and selective hydration in React 18+. It explains how to combine Suspense, streaming server APIs, and hydrateRoot to make pages interactive faster.

Which streaming APIs does this skill configure?

It instructs the agent to use renderToPipeableStream on Node environments and renderToReadableStream on Web Stream edge runtimes.

Source text

SKILL.md · MIT
---
name: react-selective-hydration
description: Teaches selective hydration combined with streaming SSR in React 18+. Use when you need to prioritize hydrating interactive components while streaming the rest of the page.
paths:
  - "**/*.tsx"
  - "**/*.jsx"
license: MIT
metadata:
  author: patterns.dev
  version: "1.1"
related_skills:
  - "hooks-pattern"
  - "hoc-pattern"
---

# Selective Hydration

In previous articles, we covered how SSR with hydration can improve user experience. React is able to (quickly) generate a tree on the server using the `renderToString` method that the `react-dom/server` library provides, which gets sent to the client after the entire tree has been generated. The rendered HTML is non interactive, until the JavaScript bundle has been fetched and loaded, after which React walks down the tree to hydrate and attaches the handlers.

However, this approach can lead to some performance issues due to some limitations with the current implementation.

## When to Use

- Use this when you want to make parts of your SSR page interactive before all JavaScript has loaded
- This is helpful when slow components (e.g., data-fetching components) are blocking the entire page's hydration

## Instructions

- Use `Suspense` boundaries to delineate independently hydratable chunks of UI
- Use `renderToPipeableStream` (Node) or `renderToReadableStream` (edge) for streaming SSR
- Place heavy data-fetching components inside `Suspense` so they don't delay sibling hydration
- Ensure critical interactive components are not inside long-lived loading fallbacks
- Use `hydrateRoot` (React 18+) to benefit from selective hydration

## Details

Before the server-rendered HTML tree is able to get sent to the client, all components need to be ready. This means that components that may rely on an external API call or any process that could cause some delays, might end up blocking smaller components from being rendered quickly.

Besides a slower tree generation, another issue is the fact that React only hydrates the tree once. This means that before React is able to hydrate any of the components, it needs to have fetched the JavaScript for all of the components before it's able to hydrate any of them. This means that smaller components (with smaller bundles) have to wait for the larger components's code to be fetched and loaded, until React is able to hydrate anything on your website. During this time, the website remained non-interactive.

React 18 solves these problems by allowing us to combine streaming server-side rendering with a new approach to hydration: Selective Hydration!

Instead of using `renderToString`, modern React SSR uses `renderToPipeableStream()` on Node runtimes or `renderToReadableStream()` on Web Stream runtimes.

These APIs, in combination with `hydrateRoot()` and `Suspense`, make it possible to start streaming HTML without having to wait for the larger components to be ready. This means that we can lazy-load components when using SSR without blocking the hydration of the rest of the page.

The `Comments` component, which earlier slowed down the tree generation and TTI, is now wrapped in `Suspense`. This tells React to not let this component slow down the rest of the tree generation. Instead, React inserts the fallback components as the initially rendered HTML, and continues to generate the rest of the tree before it's sent to the client.

In the meantime, we're still fetching the external data that we need for the `Comments` component.

Selective hydration makes it possible to already hydrate the components that were sent to the client, even before the `Comments` component has been sent!

Once the data for the `Comments` component is ready, React starts streaming the HTML for this component, as well as a small `<script>` to replace the fallback loader.

React starts the hydration after the new HTML has been injected.

React 18 fixes some issues that people often encountered when using SSR with React.

Streaming rendering allows you to start streaming components as soon as they're ready, without risking a slower FCP and TTI due to components that might take longer to generate on the server.

Components can be hydrated as soon as they're streamed to the client, since we no longer have to wait for all JavaScript to load to start hydrating and can start interacting with the app before all components have been hydrated.

## Source

- [patterns.dev/react/react-selective-hydration](https://patterns.dev/react/react-selective-hydration)

### References

- [New Suspense SSR Architecture in React 18](https://github.com/reactwg/react-18/discussions/37)

© patterns.dev · MIT · PatternsDev/skills

Similar skills

Everything for Frontend and UI →

From the same set46

hoc-pattern Teaches your AI assistant the Higher-Order Component pattern to share logic across React components. Useful for reusable auth, logging, or data fetching. CX Codex +1 1,000installs compound-pattern Teaches the agent the compound component pattern for shared implicit state. Useful for tabs, accordions and dropdowns whose parts must coordinate without explicit props. CX Codex +1 1,000installs react-server-components A skill that teaches React Server Components: which components belong on the server and where 'use client' goes. Useful in Next.js App Router. CX Codex +1 954installs progressive-hydration A skill that tells the agent how to split hydration of a server-rendered React app and defer JavaScript for non-critical sections. CX Codex +1 952installs server-side-rendering A skill that walks your agent through server-side rendering in React and tells you when SSR pays off and when static or client rendering is the better call. CX Codex +1 942installs incremental-static-rendering Teaches your coding agent Incremental Static Regeneration in Next.js. It enables background page updates and lazy generation without full site rebuilds. CX Codex +1 918installs static-rendering A skill that walks your agent through static generation: which pages can be pre-rendered to HTML at build time and how to do it in Next.js. Useful when content stays the same across requests. CX Codex +1 910installs streaming-ssr Teaches the agent to flush HTML in chunks with renderToPipeableStream and Suspense. Useful when a large page can't wait for the full tree before the first byte. CX Codex +1 883installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor