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.
npx skills add PatternsDev/skills --skill react-selective-hydration -a claude-codeWhat 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
renderToStringto streaming SSR withrenderToPipeableStreamorrenderToReadableStream - isolate slow data-fetching components behind
Suspenseboundaries - hydrate critical interactive components before all page scripts finish downloading
- configure
hydrateRootfor phased client-side hydration in React 18+
Example prompts for the agent
- Migrate our SSR setup from
renderToStringtorenderToPipeableStreamwith selective hydration - Wrap the comments widget in
Suspenseso slow API requests do not block hydration elsewhere - Check
entry.server.tsxand 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-code2Manually: put the files in place
~/.claude/skills/react-selective-hydration/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/react-selective-hydration/
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill react-selective-hydration -a codex2Manually: put the files in place
.agents/skills/react-selective-hydration/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill react-selective-hydration -a cursor2Manually: put the files in place
.cursor/skills/react-selective-hydration/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install PatternsDev/skills react-selective-hydration2Manually: put the files in place
.github/skills/react-selective-hydration/SKILL.md1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill react-selective-hydration -a gemini-cli2Platform CLI
gemini skills install https://github.com/PatternsDev/skills --path react/react-selective-hydrationManually: put the files in place
.devin/skills/react-selective-hydration/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill react-selective-hydration -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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