react-prerender-to-static-markup
v1.0.1
Published
Pre-render a React tree asynchronously to a clean string.
Maintainers
Readme
react-prerender-to-static-markup

Pre-render a React tree asynchronously to a clean markup string.
- Supports asynchronous behavior (such as components that make HTTP requests) via
prerenderToNodeStream(). - Removes Suspense streaming artifacts (via Cheerio):
- Boundary comments:
<!--$-->,<!--/$-->, etc. - Placeholder templates:
<template id="B:0">. - Hidden stream slots:
<div hidden id="S:0">. - Streaming scripts:
<script>$RC(...)</script>,<script>$RT=...</script>.
- Boundary comments:
- Returns clean static markup like
renderToStaticMarkup(), after Suspense-backed async rendering completes; conceptually, React 18’srenderToStaticNodeStream()collected to a string.
[!CAUTION]
The markup returned by this library is not hydratable. Do not use it with
hydrateRoot().
Install
npm install react-prerender-to-static-markupConsumer Usage
import prerenderToStaticMarkup from 'react-prerender-to-static-markup';
const html = await prerenderToStaticMarkup(
<html>
<head>
<title>My app</title>
</head>
<body>
<App />
</body>
</html>
);Options
From prerenderToNodeStream():
identifierPrefixonErrorsignal
From Cheerio:
Development Usage
Production Build
npm run buildTesting
The test suite can perform a single run:
npm test… or indefinitely as files are changed:
npm run test:watchTo-Do
- Probably add ESLint/Oxlint/Biome.
