Gathering detailed insights and metrics for preact-render-to-string
Gathering detailed insights and metrics for preact-render-to-string
Gathering detailed insights and metrics for preact-render-to-string
Gathering detailed insights and metrics for preact-render-to-string
@jacob-ebey/preact-render-to-string
Render JSX to an HTML string, with support for Preact components.
preact-parser
When dealing with HTML strings in Preact, our only real option is to use `dangerouslySetInnerHTML`. This is fine(-ish) if you 100% trust the contents of that HTML, but regardless, it opens up potential vectors for attack, problems and bugs. Ideally, we'd
@reggi/preact-async-render-to-string
Render JSX to an HTML string, with support for Preact components.
@yr/preact-render-to-string
Render JSX to an HTML string, with support for Preact components.
📄 Universal rendering for Preact: render JSX and Preact components to HTML.
npm install preact-render-to-string
Typescript
Module System
Node Version
NPM Version
99.4
Supply Chain
94.5
Quality
88.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
201,167,554
Last Day
351,401
Last Week
1,922,325
Last Month
8,357,334
Last Year
78,484,855
MIT License
677 Stars
608 Commits
96 Forks
9 Watchers
40 Branches
49 Contributors
Updated on May 07, 2025
Minified
Minified + Gzipped
Latest Version
6.5.13
Package Id
preact-render-to-string@6.5.13
Unpacked Size
782.04 kB
Size
234.55 kB
File Count
56
NPM Version
10.8.2
Node Version
18.20.5
Published on
Jan 13, 2025
Cumulative downloads
Total Downloads
Last Day
43.9%
351,401
Compared to previous day
Last Week
2.3%
1,922,325
Compared to previous week
Last Month
-5%
8,357,334
Compared to previous month
Last Year
48.8%
78,484,855
Compared to previous year
1
23
Render JSX and Preact components to an HTML string.
Works in Node & the browser, making it useful for universal/isomorphic rendering.
>> Cute Fox-Related Demo (@ CodePen) <<
1import { render } from 'preact-render-to-string'; 2import { h } from 'preact'; 3/** @jsx h */ 4 5let vdom = <div class="foo">content</div>; 6 7let html = render(vdom); 8console.log(html); 9// <div class="foo">content</div>
1import { render } from 'preact-render-to-string'; 2import { h, Component } from 'preact'; 3/** @jsx h */ 4 5// Classical components work 6class Fox extends Component { 7 render({ name }) { 8 return <span class="fox">{name}</span>; 9 } 10} 11 12// ... and so do pure functional components: 13const Box = ({ type, children }) => ( 14 <div class={`box box-${type}`}>{children}</div> 15); 16 17let html = render( 18 <Box type="open"> 19 <Fox name="Finn" /> 20 </Box> 21); 22 23console.log(html); 24// <div class="box box-open"><span class="fox">Finn</span></div>
1import express from 'express'; 2import { h } from 'preact'; 3import { render } from 'preact-render-to-string'; 4/** @jsx h */ 5 6// silly example component: 7const Fox = ({ name }) => ( 8 <div class="fox"> 9 <h5>{name}</h5> 10 <p>This page is all about {name}.</p> 11 </div> 12); 13 14// basic HTTP server via express: 15const app = express(); 16app.listen(8080); 17 18// on each request, render and return a component: 19app.get('/:fox', (req, res) => { 20 let html = render(<Fox name={req.params.fox} />); 21 // send it back wrapped up as an HTML5 document: 22 res.send(`<!DOCTYPE html><html><body>${html}</body></html>`); 23});
Rendering errors can be caught by Preact via getDerivedStateFromErrors
or componentDidCatch
. To enable that feature in preact-render-to-string
set errorBoundaries = true
1import { options } from 'preact'; 2 3// Enable error boundaries in `preact-render-to-string` 4options.errorBoundaries = true;
Suspense
& lazy
components with preact/compat
1npm install preact preact-render-to-string
1export default () => { 2 return <h1>Home page</h1>; 3};
1import { Suspense, lazy } from 'preact/compat'; 2 3// Creation of the lazy component 4const HomePage = lazy(() => import('./pages/home')); 5 6const Main = () => { 7 return ( 8 <Suspense fallback={<p>Loading</p>}> 9 <HomePage /> 10 </Suspense> 11 ); 12};
1import { renderToStringAsync } from 'preact-render-to-string'; 2import { Main } from './main'; 3 4const main = async () => { 5 // Rendering of lazy components 6 const html = await renderToStringAsync(<Main />); 7 8 console.log(html); 9 // <h1>Home page</h1> 10}; 11 12// Execution & error handling 13main().catch((error) => { 14 console.error(error); 15});
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
2 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
55 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More