All Projects → valcol → react-hydration-on-demand

valcol / react-hydration-on-demand

Licence: MIT License
Hydrate your React components only when you need to

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-hydration-on-demand

React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (+371.28%)
Mutual labels:  ssr, code-splitting
Hapi React Hot Loader Example
Simple React Hot Loading example with Hapi Server-side rendering
Stars: ✭ 44 (-53.19%)
Mutual labels:  ssr, code-splitting
React Imported Component
✂️📦Bundler-independent solution for SSR-friendly code-splitting
Stars: ✭ 525 (+458.51%)
Mutual labels:  ssr, code-splitting
React Loadable
⏳ A higher order component for loading components with promises.
Stars: ✭ 16,238 (+17174.47%)
Mutual labels:  ssr, code-splitting
React Ssr Boilerplate
Boilerplate for React apps with routing, code splitting, & server side rendering
Stars: ✭ 183 (+94.68%)
Mutual labels:  ssr, code-splitting
Loadable Components
The recommended Code Splitting library for React ✂️✨
Stars: ✭ 6,194 (+6489.36%)
Mutual labels:  ssr, code-splitting
Typescript Hapi React Hot Loader Example
Simple TypeScript React Hot Loading example with Hapi Server-side rendering
Stars: ✭ 44 (-53.19%)
Mutual labels:  ssr, code-splitting
Hyperapp Render
Render Hyperapp to an HTML string with SSR and Node.js streaming support.
Stars: ✭ 93 (-1.06%)
Mutual labels:  ssr, render
Koa React Universal
lightweight React-Koa2 universal boilerplate, only what is essential
Stars: ✭ 112 (+19.15%)
Mutual labels:  ssr, code-splitting
React Async Component
Resolve components asynchronously, with support for code splitting and advanced server side rendering use cases.
Stars: ✭ 1,441 (+1432.98%)
Mutual labels:  ssr, code-splitting
isomorphic-react-redux-saga-ssr
Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting
Stars: ✭ 19 (-79.79%)
Mutual labels:  ssr, code-splitting
React Pwa
An upgradable boilerplate for Progressive web applications (PWA) with server side rendering, build with SEO in mind and achieving max page speed and optimized user experience.
Stars: ✭ 2,433 (+2488.3%)
Mutual labels:  ssr, code-splitting
Modern-Web-App
React PWA with SSR and Code splitting
Stars: ✭ 45 (-52.13%)
Mutual labels:  ssr, code-splitting
ssr-starter-pack
Moved to https://github.com/Brigad/ssr-starter-pack
Stars: ✭ 12 (-87.23%)
Mutual labels:  ssr
onurl
URL Shortener created w/ Next.js, TypeScript, Mongoose
Stars: ✭ 48 (-48.94%)
Mutual labels:  ssr
react-easy-ssr
🔥 React Starter Project with Webpack 5, Babel 7, TypeScript, Redux-saga, Styled-components, React-jss, Split code, Server Side Rendering.
Stars: ✭ 31 (-67.02%)
Mutual labels:  ssr
perf
PERF is an Exhaustive Repeat Finder
Stars: ✭ 26 (-72.34%)
Mutual labels:  ssr
greenwood
Greenwood is your workbench for the web, focused on supporting modern web standards and development to help you create your next project.
Stars: ✭ 48 (-48.94%)
Mutual labels:  ssr
nuxt-plesk-example
No description or website provided.
Stars: ✭ 27 (-71.28%)
Mutual labels:  ssr
my-blog
🐬 个人技术博客(基于vue的服务端渲染 nuxt.js)
Stars: ✭ 94 (+0%)
Mutual labels:  ssr

react-hydration-on-demand - Progressive hydration made easy 💧

GitHub Workflow Status npm bundle size npm npm

Hydrate your component rendered server-side only when needed to relieve the main thread, thus improving TTI, TBT and FID. Can be used with a code-splitting library to load the component code at runtime right before the hydration step and reduce the initial payload size of your application.

Install

npm

npm install react-hydration-on-demand --save

yarn

yarn add react-hydration-on-demand

How to use

import withHydrationOnDemand from "react-hydration-on-demand";
import Card from "../Card";

//Hydrate when the component enters the viewport
const CardWithHydrationOnDemand = withHydrationOnDemand({ on: ["visible"] })(
    Card
);

//Hydrate when the browser's event loop is idle
const CardWithHydrationOnDemand = withHydrationOnDemand({ on: ["idle"] })(Card);

//Hydrate after a delay (by default: 2000ms)
const CardWithHydrationOnDemand = withHydrationOnDemand({ on: ["delay"] })(
    Card
);

//Hydrate after a custom delay (3000ms)
const CardWithHydrationOnDemand = withHydrationOnDemand({
    on: [["delay", 3000]],
})(Card);

//Hydrate when the user scroll on the document
const CardWithHydrationOnDemand = withHydrationOnDemand({
    on: [["scroll", () => document]],
})(Card);

//Hydrate when the when the browser's event loop is idle or when the user scroll, whichever comes first
const CardWithHydrationOnDemand = withHydrationOnDemand({
    on: ["idle", "visible"],
})(Card);

//Load an async chunck before hydration
import loadable from "@loadable/component";

const LoadableCard = loadable(() => import("../Card"));
const CardWithHydrationOnDemand = withHydrationOnDemand({
    on: [["scroll", () => document]],
    onBefore: LoadableCard.load,
})(LoadableCard);

//Never hydrate unless forceHydrate is set to true in the props
const CardWithHydrationOnDemand = withHydrationOnDemand()(Card);

//...

export default class App extends React.Component {
    render() {
        return <CardWithHydrationOnDemand title="my card" />;
    }
}

What if my component is also used client side only ?

If the component isn't rendered server side, it will render directly and behave normally.

Options

on: Array

An array of events who will trigger the hydration. Can contains event names directly or as an array of ['event name', options].

import withHydrationOnDemand from "react-hydration-on-demand";
import Card from "../Card";

const CardWithHydrationOnDemand = withHydrationOnDemand({
    on: ["visible", ["scroll", () => document], ["delay", 5000]],
})(Card);

Support all DOM events and more :

Event name Options Description
all DOM events getTarget: Function who return the event target (default: the wrapped component)
delay delay: Number in ms (default value: 2000) Scheduled hydration.
visible getOptions: Function who return an intersectionObserver options object (default: no options) Requires IntersectionObserver. Polyfill not included. If unsupported the component is directy hydrated.
idle Requires requestIdleCallback. Polyfill not included. If unsupported the component will be hydrated with a delay of 2000ms.

onBefore: Promise (optional)

Promise to resolve before hydration.

Can be usefull if you need to preload chunks before hydration for example.

import withHydrationOnDemand from "react-hydration-on-demand";
import loadable from "@loadable/component";

const LoadableCard = loadable(() => import("../Card"));
const CardWithHydrationOnDemand = withHydrationOnDemand({
    on: ["visible"],
    onBefore: LoadableCard.load,
})(LoadableCard);

whenInputPending: Boolean (optional, default: false)

When set to true use navigator.scheduling.isInputPending to check if there is a pending user input on mount. If that's the case, hydration will be delayed using the strategies defined in the on option to allow the browser to handle the user input. If there is no pending input, the component will be hydrated directly to be interactive as fast as possible.

See https://github.com/WICG/is-input-pending for more infos.

isInputPendingFallbackValue: Boolean (optional, default: true)

The default value returned on browsers who don't implements navigator.scheduling.isInputPending when whenInputPending set to true.

disableFallback: Boolean (optional, default: false)

If set at true the component will not be rendered client side if not rendered server side.

Props

wrapperProps: Object (optional)

Props that are applied to the div which wraps the provided component.

import withHydrationOnDemand from "react-hydration-on-demand";
import Card from "../Card";

const CardWithHydrationOnDemand = withHydrationOnDemand({ on: ["delay"] })(
    Card
);

export default class App extends React.Component {
    render() {
        return (
            <CardWithHydrationOnDemand
                title="my card"
                wrapperProps={{
                    className: "customClassName",
                    style: { display: "contents" },
                }}
            />
        );
    }
}

forceHydration: Boolean (optional, default: false)

Force the hydration of the component.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].