Gathering detailed insights and metrics for preact-ssr-prepass
Gathering detailed insights and metrics for preact-ssr-prepass
Gathering detailed insights and metrics for preact-ssr-prepass
Gathering detailed insights and metrics for preact-ssr-prepass
npm install preact-ssr-prepass
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
49 Stars
76 Commits
7 Forks
3 Watching
12 Branches
21 Contributors
Updated on 22 Nov 2024
JavaScript (97.4%)
TypeScript (2.6%)
Cumulative downloads
Total Downloads
Last day
-22.6%
1,356
Compared to previous day
Last week
-3%
7,656
Compared to previous week
Last month
-9.8%
35,087
Compared to previous month
Last year
-1.3%
616,961
Compared to previous year
Drop-in replacement for
react-ssr-prepass
.
Neither Preact nor React support Suspense
on the server as of now. Heavily inspired by react-ssr-prepass
, preact-ssr-prepass
provides a two-pass approach with which Suspense
can be used on the server. In the first pass, preact-ssr-prepass
will create a VNode tree and await all suspensions, in the second pass preact-render-to-string
can be used to render a vnode to a string.
Even if preact-ssr-prepass
is designed to do as little as possible, it still adds a slight
overhead since the VNode tree is created twice.
⚠️ Note that this is neither an official Preact nor React API and that the way Suspense
is handled
on the server might/will change in the future!
preact-ssr-prepass
needs to be called just before rendering a vnode to a string. See the following
example:
lazy.js:
1export default function LazyLoaded() { 2 return <div>I shall be loaded and rendered on the server</div> 3}
index.js:
1import { createElement as h } from 'preact'; 2import { Suspense, lazy } from 'preact/compat'; 3import renderToString from 'preact-render-to-string'; 4import prepass from 'preact-ssr-prepass'; 5 6const LazyComponent = lazy(() => import('./lazy')); 7 8const vnode = ( 9 <Suspense fallback={<div>I shall not be rendered on the server</div>}> 10 <LazyComponent /> 11 </Suspense> 12); 13 14prepass(vnode) 15 .then(() => { 16 // <div>I shall be loaded and rendered on the server</div> 17 console.log(renderToString(vnode)); 18 });
preact-ssr-prepass
accepts a second argument that allows you to suspend on arbitrary elements:
1ssrPrepass(<App />, (element, instance) => { 2 if (instance !== undefined && typeof instance.fetchData === 'function') { 3 return instance.fetchData() 4 } 5});
1/** 2 * Visitor function to suspend on certain elements. 3 * 4 * When this function returns a Promise it is awaited before the vnode will be rendered. 5 */ 6type Visitor = (element: preact.VNode, instance: ?preact.Component) => ?Promise<any>; 7 8/** 9 * The default export of preact-ssr-prepass 10 * 11 * @param{vnode} preact.VNode The vnode to traverse 12 * @param{visitor} ?Visitor A function that is called for each vnode and might return a Promise to suspend. 13 * @param{context} ?Object Initial context to be used when traversing the vnode tree 14 * @return Promise<any> Promise that will complete once the complete vnode tree is traversed. Note that even if 15 * a Suspension throws the returned promise will resolve. 16 */ 17export default function prepass(vnode: preact.VNode, visitor?: Visitor, context:? Object): Promise<any>;
react-ssr-prepass
is usually used on the server only and not bundled into your bundles but rather
required through Node.js. To alias react-ssr-prepass
to preact-ssr-prepass
we recommend to use
module-alias
:
Create a file named alias.js
:
1const moduleAlias = require('module-alias')
2
3module.exports = () => {
4 moduleAlias.addAlias('react-ssr-prepass', 'preact-ssr-prepass')
5}
Require and execute the exported function in your applications entrypoint (before require'ing react-ssr-prepass
):
1require('./alias')();
react-ssr-prepass
The visitor passed to preact-ssr-prepass
gets a Preact element instead of a React one. When you use preact/compat
's createElement
it will make the element/vnode look as similar to a React element as possible.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
Found 8/13 approved changesets -- score normalized to 6
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
33 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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