Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-ssr-prepass

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-ssr-prepass

A custom partial React SSR renderer for prefetching and suspense

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
71K
decreased by-15.91%
Maintainers
1
Weekly downloads
 
Created
Source

react-ssr-prepass 🌲

react-ssr-prepass is a partial server-side React renderer that is meant to do a prepass on a React tree and await all suspended promises. It also accepts a visitor function that can be used to await on custom promises.

It's meant to be used for fetching data before executing renderToString or renderToNodeStream and provides a crude way to support suspense during SSR today. ✨

⚠️ Disclaimer: Suspense is unstable and experimental. Its API may change and hence this library may break. Awaiting promises is only part of the story and does not mean that any data will be rehydrated on the client automatically. There be dragons!

Quick Start Guide

First install react-ssr-prepass alongside react and react-dom:

yarn add react-ssr-prepass
# or
npm install --save react-ssr-prepass

In your SSR code you may now add it in front of your usual renderToString or renderToNodeStream code:

import { createElement } from 'react'
import { renderToString } from 'react-dom/server'

import ssrPrepass from 'react-ssr-prepass'

const renderApp = async App => {
  const element = createElement(App)
  await ssrPrepass(element)

  return renderToString(element)
}

You should also be aware that react-ssr-prepass does not handle any data rehydration. In most cases it's fine to collect data from your cache or store after running ssrPrepass, turn it into JSON, and send it down in your HTML result.

Prior Art

This library is mostly based on react-dom's ReactPartialRenderer implementation. Its API and purpose is based on react-apollo's getDataFromTree function and hence it's also a successor to react-tree-walker.

FAQs

Package last updated on 15 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc