skills/bun-guides-ecosystem-ssr-react/SKILL.md
Server-side render (SSR) a React component
npx skillsauth add jarle/bun-skills Bun Server-side render (SSR) a React componentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
To get started, install react & react-dom:
# Any package manager can be used
bun add react react-dom
To render a React component to an HTML stream server-side (SSR):
import { renderToReadableStream } from "react-dom/server";
function Component(props: { message: string }) {
return (
<body>
<h1>{props.message}</h1>
</body>
);
}
const stream = await renderToReadableStream(<Component message="Hello from server!" />);
Combining this with Bun.serve(), we get a simple SSR HTTP server:
Bun.serve({
async fetch() {
const stream = await renderToReadableStream(<Component message="Hello from server!" />);
return new Response(stream, {
headers: { "Content-Type": "text/html" },
});
},
});
React 19 and later includes an SSR optimization that takes advantage of Bun's "direct" ReadableStream implementation. If you run into an error like export named 'renderToReadableStream' not found, please make sure to install version 19 of react & react-dom, or import from react-dom/server.browser instead of react-dom/server. See facebook/react#28941 for more information.
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling