server-side-rendering — Claude Code skill: SSR for React
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.
npx skills add PatternsDev/skills --skill server-side-rendering -a claude-codeWhat server-side-rendering does
The skill activates on **/*.tsx and **/*.jsx files and works through how SSR behaves: the server returns full HTML for each request, pulling data from a datastore or an external API on the same pass. No client-side rendering code ships to the browser, so the first content shows up sooner and crawlers get real markup.
Inside are sections on when to use SSR and when to skip it, plus instructions and examples. The agent will point you at a framework with built-in support such as Next.js, at renderToPipeableStream from React 18+ for streaming with Suspense, and at hydration for pages that need interactivity. There is a walkthrough of getServerSideProps() that fetches data and passes it to the component as props.
TTFB is the catch. Every request is processed from scratch, so heavy concurrent traffic, a slow network or unoptimised server code all delay the response. Some interactions still need a full page reload, which rules out a single-page application on plain SSR. For internal dashboards where SEO does not matter, the skill itself advises against SSR. Install runs through npx skills add, licensed MIT.
What it helps with
- ship real HTML to search engines instead of an empty shell
- cut time to first content on data-heavy pages
- fetch from an API on the server and hand the result to a component
- decide between SSR, static rendering and client rendering for one page
- move a page to streaming with Suspense
Example prompts for the agent
- Set up SSR for a user list page in Next.js
- Should this page use server-side rendering or is static enough?
- Rewrite this component around
getServerSideProps()with a data fetch
How to install server-side-rendering
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill server-side-rendering -a claude-code2Manually: put the files in place
~/.claude/skills/server-side-rendering/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/server-side-rendering/
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill server-side-rendering -a codex2Manually: put the files in place
.agents/skills/server-side-rendering/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill server-side-rendering -a cursor2Manually: put the files in place
.cursor/skills/server-side-rendering/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install PatternsDev/skills server-side-rendering2Manually: put the files in place
.github/skills/server-side-rendering/SKILL.md1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill server-side-rendering -a gemini-cli2Platform CLI
gemini skills install https://github.com/PatternsDev/skills --path react/server-side-renderingManually: put the files in place
.devin/skills/server-side-rendering/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill server-side-rendering -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 server-side-rendering
How do I install server-side-rendering in Claude?
Run npx skills add PatternsDev/skills --skill server-side-rendering -a claude-code. The skill file lands at ~/.claude/skills/server-side-rendering/SKILL.md.
What does server-side-rendering do?
It teaches the agent server-side rendering for React: when it fits, how to pair SSR with hydration, and which frameworks support it out of the box.
When should I avoid SSR?
For purely static content where SSG is enough, and for internal dashboards where SEO is irrelevant. High per-request rendering cost with no room for caching is another reason to skip it.
Source text
SKILL.md · MIT
---
name: server-side-rendering
description: Teaches server-side rendering (SSR) for React applications. Use when you need faster initial page loads, better SEO, or dynamic per-request HTML generation.
paths:
- "**/*.tsx"
- "**/*.jsx"
license: MIT
metadata:
author: patterns.dev
version: "1.1"
related_skills:
- "hooks-pattern"
- "hoc-pattern"
---
# Server-side Rendering
## Table of Contents
- [When to Use](#when-to-use)
- [When NOT to Use](#when-not-to-use)
- [Instructions](#instructions)
- [Details](#details)
- [Source](#source)
Server-side rendering (SSR) is one of the oldest methods of rendering web content. SSR generates the full HTML for the page content to be rendered in response to a user request. The content may include data from a datastore or external API.
The connect and fetch operations are handled on the server. HTML required to format the content is also generated on the server. Thus, with SSR we can avoid making additional round trips for data fetching and templating. As such, rendering code is not required on the client and the JavaScript corresponding to this need not be sent to the client.
## When to Use
- Use this when SEO and fast First Contentful Paint are important for your application
- This is helpful for content-heavy pages that need to be quickly visible to users and search engines
## When NOT to Use
- For purely static content where static rendering (SSG) is sufficient and avoids per-request server cost
- For internal dashboards or tools where SEO is irrelevant and CSR provides a simpler architecture
- When the server rendering overhead per request is too high and caching isn't feasible
## Instructions
- Use frameworks like Next.js that provide built-in SSR support
- Consider upgrading to `renderToPipeableStream` (React 18+) for streaming SSR with Suspense support
- Combine SSR with client-side hydration for interactive pages
- Be aware of TTFB implications — optimize server response times and consider caching
- Explore React Server Components as a complement to SSR for reducing client-side JavaScript
## Details
With SSR every request is treated independently and will be processed as a new request by the server. Even if the output of two consecutive requests is not very different, the server will process and generate it from scratch. Since the server is common to multiple users, the processing capability is shared by all active users at a given time.
### Classic SSR Implementation
Consider a simple example showing and updating the current time on a page using classic SSR and JavaScript.
```html
<!DOCTYPE html>
<html>
<head>
<title>Time</title>
</head>
<body>
<div>
<h1>Hello, world!</h1>
<b>It is <div id=currentTime></div></b>
</div>
</body>
</html>
```
```js
function tick() {
var d = new Date();
var n = d.toLocaleTimeString();
document.getElementById("currentTime").innerHTML = n;
}
setInterval(tick, 1000);
```
Note how this is different from the CSR code that provides the same output. Also note that, while the HTML is rendered by the server, the time displayed here is the local time on the client as populated by the JavaScript function `tick()`. If you want to display any other data that is server specific, e.g., server time, you will need to embed it in the HTML before it is rendered. This means it will not get refreshed automatically without a round trip to the server.
### Pros and Cons
Executing the rendering code on the server and reducing JavaScript offers the following advantages.
#### Lesser JavaScript leads to quicker FCP and TTI
In cases where there are multiple UI elements and application logic on the page, SSR has considerably less JavaScript when compared to CSR. The time required to load and process the script is thus lesser. FP, FCP and TTI are shorter and FCP = TTI. With SSR, users will not be left waiting for all the screen elements to appear and for it to become interactive.
#### Provides additional budget for client-side JavaScript
Development teams are required to work with a JS budget that limits the amount of JS on the page to achieve the desired performance. With SSR, since you are directly eliminating the JS required to render the page, it creates additional space for any third party JS that may be required by the application.
#### SEO enabled
Search engine crawlers are easily able to crawl the content of an SSR application thus ensuring higher search engine optimization on the page.
SSR works great for static content due to the above advantages. However, it does have a few disadvantages because of which it is not perfect for all scenarios.
#### Slow TTFB
Since all processing takes place on the server, the response from the server may be delayed in case of one or more of the following scenarios:
- Multiple simultaneous users causing excess load on the server.
- Slow network
- Server code not optimized.
#### Full page reloads required for some interactions
Since all code is not available on the client, frequent round trips to the server are required for all key operations causing full page reloads. This could increase the time between interactions as users are required to wait longer between operations. A single-page application is thus not possible with SSR.
### SSR with Next.js
The Next.js framework also supports SSR. This pre-renders a page on the server on every request. It can be accomplished by exporting an async function called [`getServerSideProps()`](https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering) from a page as follows.
```js
export async function getServerSideProps(context) {
return {
props: {}, // will be passed to the page component as props
};
}
```
The context object contains keys for HTTP request and response objects, routing parameters, querystring, locale, etc.
The following implementation shows the use of `getServerSideProps()` for rendering data on a page formatted using React:
```js
// data fetched from an external data source using `getServerSideProps`
const Users = ({ users, error }) => {
return (
<section>
<header>
<h1>List of users</h1>
</header>
{error && <div>There was an error.</div>}
{!error && users && (
<table>
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{users.map((user, key) => (
<tr key={key}>
<td>{user.username}</td>
<td>{user.email}</td>
<td>{user.name}</td>
</tr>
))}
</tbody>
</table>
)}
</section>
);
};
export async function getServerSideProps() {
try {
// Fetch data from external API
const res = await fetch("https://jsonplaceholder.typicode.com/users");
const data = await res.json();
// Pass data to the page via props
return { props: { users: data, error: null } };
} catch (error) {
return { props: { users: null, error: true } };
}
}
export default Users;
```
### React for the Server
React can be rendered isomorphically, which means that it can function both on the browser as well as other platforms like the server. Thus, UI elements may be rendered on the server using React.
React can also be used with universal code which will allow the same code to run in multiple environments. This is made possible by using Node.js on the server.
```js
ReactDOMServer.renderToString(element);
```
This function returns an HTML string corresponding to the React element. The HTML can then be rendered to the client for a faster page load.
The `renderToString()` function may be used with `hydrateRoot()`. This preserves the HTML rendered on the server and attaches event handlers on the client.
To implement this, we use a `.js` file on both client and server corresponding to every page. The `.js` file on the server will render the HTML content, and the `.js` file on the client will hydrate it.
The server code:
```js
app.get("/", (req, res) => {
const app = ReactDOMServer.renderToString(<App />);
});
```
The client-side code to ensure the element `App` is hydrated:
```js
import { hydrateRoot } from "react-dom/client";
hydrateRoot(document.getElementById("root"), <App />);
```
A complete example of SSR with React can be found [here](https://www.digitalocean.com/community/tutorials/react-server-side-rendering).
## Source
- [patterns.dev/react/server-side-rendering](https://patterns.dev/react/server-side-rendering)
© patterns.dev · MIT · PatternsDev/skills