All Projects → kriasoft → Hyperapp Render

kriasoft / Hyperapp Render

Licence: mit
Render Hyperapp to an HTML string with SSR and Node.js streaming support.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Hyperapp Render

Rapscallion
Asynchronous React VirtualDOM renderer for SSR.
Stars: ✭ 1,405 (+1410.75%)
Mutual labels:  stream, render, server-side-rendering
Angular Ssr Swa
Stars: ✭ 15 (-83.87%)
Mutual labels:  ssr, server-side-rendering
React Lazy Load Image Component
React Component to lazy load images and components using a HOC to track window scroll position.
Stars: ✭ 755 (+711.83%)
Mutual labels:  ssr, server-side-rendering
Egg Vue Webpack Boilerplate
Egg Vue Server Side Render (SSR) / Client Side Render (CSR)
Stars: ✭ 1,302 (+1300%)
Mutual labels:  ssr, server-side-rendering
React Imported Component
✂️📦Bundler-independent solution for SSR-friendly code-splitting
Stars: ✭ 525 (+464.52%)
Mutual labels:  ssr, server-side-rendering
Loadable Components
The recommended Code Splitting library for React ✂️✨
Stars: ✭ 6,194 (+6560.22%)
Mutual labels:  ssr, server-side-rendering
Typescript Hapi React Hot Loader Example
Simple TypeScript React Hot Loading example with Hapi Server-side rendering
Stars: ✭ 44 (-52.69%)
Mutual labels:  ssr, server-side-rendering
React Firebase Starter
Boilerplate (seed) project for creating web apps with React.js, GraphQL.js and Relay
Stars: ✭ 4,366 (+4594.62%)
Mutual labels:  ssr, server-side-rendering
React Use Api
Async HTTP request data for axios. Designed for diverse UI states, SSR and data pre-caching.
Stars: ✭ 49 (-47.31%)
Mutual labels:  ssr, server-side-rendering
Ssr Window
Better handling for window object in SSR environment
Stars: ✭ 55 (-40.86%)
Mutual labels:  ssr, server-side-rendering
Rpg Boilerplate
Relay (React), Postgres, and Graphile (GraphQL): A Modern Frontend and API Boilerplate
Stars: ✭ 62 (-33.33%)
Mutual labels:  ssr, server-side-rendering
Universal Starter
Angular 9 Universal repo with many features
Stars: ✭ 518 (+456.99%)
Mutual labels:  ssr, server-side-rendering
Laravel Server Side Rendering
Server side rendering JavaScript in your Laravel application
Stars: ✭ 506 (+444.09%)
Mutual labels:  ssr, server-side-rendering
React App
Create React App with server-side code support
Stars: ✭ 614 (+560.22%)
Mutual labels:  ssr, server-side-rendering
Nuxt Firebase Sns Example
Nuxt v2 & Firebase(Hosting / Functions SSR / Firestore), Google Auth SNS Example.
Stars: ✭ 485 (+421.51%)
Mutual labels:  ssr, server-side-rendering
Onthefly
🔗 Generate TinySVG, HTML and CSS on the fly
Stars: ✭ 37 (-60.22%)
Mutual labels:  ssr, server-side-rendering
React Redux Saucepan
A minimal and universal react redux starter project. With hot reloading, linting and server-side rendering
Stars: ✭ 86 (-7.53%)
Mutual labels:  ssr, server-side-rendering
React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (+376.34%)
Mutual labels:  ssr, server-side-rendering
React Snap
👻 Zero-configuration framework-agnostic static prerendering for SPAs
Stars: ✭ 4,565 (+4808.6%)
Mutual labels:  ssr, server-side-rendering
Hapi React Hot Loader Example
Simple React Hot Loading example with Hapi Server-side rendering
Stars: ✭ 44 (-52.69%)
Mutual labels:  ssr, server-side-rendering

Hyperapp Render

npm version npm downloads library size slack chat

This library is allowing you to render Hyperapp views to an HTML string.

  • User experience — Generate HTML on the server and send the markup down on the initial request for faster page loads. Built-in mounting feature in Hyperapp is allowing you to have a very performant first-load experience.
  • Accessibility — Allow search engines to crawl your pages for SEO purposes.
  • TestabilityCheck HTML validity and use snapshot testing to improve quality of your software.

Getting Started

Our first example is an interactive app from which you can generate an HTML markup. Go ahead and try it online.

import { h } from 'hyperapp'
import { renderToString } from 'hyperapp-render'

const state = {
  text: 'Hello'
}

const actions = {
  setText: text => ({ text })
}

const view = (state, actions) => (
  <main>
    <h1>{state.text.trim() === '' ? '👋' : state.text}</h1>
    <input value={state.text} oninput={e => actions.setText(e.target.value)} />
  </main>
)

const html = renderToString(view(state, actions))

console.log(html) // => <main><h1>Hello</h1><input value="Hello"/></main>

Looking for a boilerplate? Try Hyperapp Starter with pre-configured server-side rendering and many more.

Installation

Using npm:

npm install hyperapp-render --save

Or using a CDN like unpkg.com or jsDelivr with the following script tag:

<script src="https://unpkg.com/hyperapp-render"></script>

You can find the library in window.hyperappRender.

We support all ES5-compliant browsers, including Internet Explorer 9 and above, but depending on your target browsers you may need to include polyfills for Set and Map before any other code.

Usage

The library provides two functions which you can use depending on your needs or personal preferences:

import { renderToString, renderToStream } from 'hyperapp-render'

renderToString(<Component />)        // => <string>
renderToString(view(state, actions)) // => <string>
renderToString(view, state, actions) // => <string>

renderToStream(<Component />)        // => <stream.Readable> => <string>
renderToStream(view(state, actions)) // => <stream.Readable> => <string>
renderToStream(view, state, actions) // => <stream.Readable> => <string>

Note: renderToStream is available from Node.js environment only (v6 or newer).

Overview

You can use renderToString function to generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.

If you call hyperapp.app() on a node that already has this server-rendered markup, Hyperapp will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.

The renderToStream function returns a Readable stream that outputs an HTML string. The HTML output by this stream is exactly equal to what renderToString would return. By using this function you can reduce TTFB and improve user experience even more.

Caveats

The library automatically escapes text content and attribute values of virtual DOM nodes to protect your application against XSS attacks. However, it is not safe to allow "user input" for node names or attribute keys:

const Node = 'div onclick="alert()"'
renderToString(<Node title="XSS">Hi</Node>)
// => <div onclick="alert()" title="XSS">Hi</div>

const attributes = { 'onclick="alert()" title': 'XSS' }
renderToString(<div {...attributes}>Hi</div>)
// => <div onclick="alert()" title="XSS">Hi</div>

const userInput = '<script>alert()</script>'
renderToString(<div title="XSS" innerHTML={userInput}>Hi</div>)
// => <div title="XSS"><script>alert()</script></div>

License

Hyperapp Render is MIT licensed. See LICENSE.

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].