All Projects → marvinhagemeister → preact-server-renderer

marvinhagemeister / preact-server-renderer

Licence: MIT License
Server side rendering of preact components

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to preact-server-renderer

React Storefront
React Storefront - PWA for eCommerce. 100% offline, platform agnostic, headless, Magento 2 supported. Always Open Source, Apache-2.0 license. Join us as contributor ([email protected]).
Stars: ✭ 292 (+342.42%)
Mutual labels:  preact, ssr
preact-polka-ssr
Preact SSR using Polka
Stars: ✭ 27 (-59.09%)
Mutual labels:  preact, ssr
React Storefront
Build and deploy e-commerce progressive web apps (PWAs) in record time.
Stars: ✭ 275 (+316.67%)
Mutual labels:  preact, ssr
Preact Cli Ssr
A quick demo for adding SSR to a Preact CLI app
Stars: ✭ 76 (+15.15%)
Mutual labels:  preact, ssr
Preact Redux Isomorphic
preact-redux-isomorphic PWA SPA SSR best practices and libraries in under 80kB page size (for live demo click the link below)
Stars: ✭ 85 (+28.79%)
Mutual labels:  preact, ssr
Hydux
A light-weight type-safe Elm-like alternative for Redux ecosystem, inspired by hyperapp and Elmish
Stars: ✭ 216 (+227.27%)
Mutual labels:  preact, ssr
Goober
🥜 goober, a less than 1KB 🎉 css-in-js alternative with a familiar API
Stars: ✭ 2,317 (+3410.61%)
Mutual labels:  preact, ssr
personal-website
Personal website – made with Next.js, Preact, MDX, RMWC, & Vercel
Stars: ✭ 16 (-75.76%)
Mutual labels:  preact, ssr
reph
Phoenix/React application starter kit
Stars: ✭ 15 (-77.27%)
Mutual labels:  ssr
react-kits
⚔️ Opinionated Fullstack React toolkits featuring project generation, dev server, build production bundle, and common dev-tools. This is simple DIY create-react-app.
Stars: ✭ 13 (-80.3%)
Mutual labels:  ssr
onurl
URL Shortener created w/ Next.js, TypeScript, Mongoose
Stars: ✭ 48 (-27.27%)
Mutual labels:  ssr
eventrix
Open-source, Predictable, Scaling JavaScript library for state managing and centralizing application global state. State manage system for react apps.
Stars: ✭ 35 (-46.97%)
Mutual labels:  ssr
desvg
🌅 Converts SVG files into components 🌞
Stars: ✭ 79 (+19.7%)
Mutual labels:  preact
stoxy
Stoxy is a state management API for all modern Web Technologies
Stars: ✭ 73 (+10.61%)
Mutual labels:  preact
node.umelabs.dev
每天24:00点前更新免费SS/SSR节点
Stars: ✭ 1,135 (+1619.7%)
Mutual labels:  ssr
nuxt-plesk-example
No description or website provided.
Stars: ✭ 27 (-59.09%)
Mutual labels:  ssr
nashorn-polyfill
Polyfill to Nashorn engine with web api
Stars: ✭ 56 (-15.15%)
Mutual labels:  ssr
jasonformat.com
My blog
Stars: ✭ 18 (-72.73%)
Mutual labels:  preact
angular-pwa
Angular 13 Example Progressive Web App (PWA)
Stars: ✭ 45 (-31.82%)
Mutual labels:  ssr
v2ray
每日分享免费节点、免费机场、ssr节点、v2ray节点、v2ray订阅、clash节点、clash订阅、shadowrocket订阅、Quantumult X订阅、Clash .NET订阅、小火箭节点、小猫咪节点、免费翻墙、免费科学上网、免费梯子、免费trojan节点、蓝灯、谷歌商店、翻墙梯子、安卓VPN、iphone翻墙节点、iphone vpn、一键翻墙浏览器、节点分享、免费SSR、蓝灯、谷歌商店、V2ary免费节点、代理、proxy代理科学上网、TG代理、电报代理、Telegram代理、ip加速、翻墙软件、socks5、破解VPN、机场推荐、节点订阅、破解VPN
Stars: ✭ 525 (+695.45%)
Mutual labels:  ssr

Preact Server Renderer

preact-server-render is similar to preact-render-to-string by @developit (author of preact), but with pluggable formatters. This means you can easily tailer the output to your needs, without any overhead. Wether you have a snapshot renderer, or a custom format in mind. Performance wise, both libraries are equal, only the jsx renderer is a tiny bit faster here.

Installation

# npm
npm install preact-server-renderer

# yarn
yarn add preact-server-renderer

Usage

const {
  createRenderer,
  CompactRenderer,
  JsxRenderer,
} = require("preact-server-renderer");

// Default rendering
const render = createRenderer(new CompactRenderer());
const html = render(<div />);

// JSX rendering
const renderJsx = createRenderer(new JsxRenderer());
const html2 = renderJsx(<div />);

// shallow rendering
const shallow = createRenderer(new CompactRenderer(), { shallow: true });
const html3 = shallow(<div />);

CompactRenderer

The CompactRenderer is the standard html renderer. It doesn't add any whitespace and simply renders the components to a string.

Example:

const { createRenderer, CompactRenderer } = require("preact-server-renderer");

const render = createRenderer(new CompactRenderer());
console.log(
  render(
    <div class="foo">
      <h1>Hello</h1>
    </div>,
  ),
);

Output:

<div class="foo"><h1>Hello</h1></div>

JsxRenderer

This one is meant for snapshot tests, like they are found in jest.

Example:

const { createRenderer, JsxRenderer } = require("preact-server-renderer");

const render = createRenderer(new JsxRenderer());
console.log(
  render(
    <div class="foo">
      <h1>Hello</h1>
    </div>,
  ),
);

Output:

<div
  class="foo"
>
  <h1>
    Hello
  </h1>
</div>

Writing A Custom Renderer

This is where this library really shines. Custom renderers can be easily plugged into the createRenderer function. They basically have a few callbacks for the specific parsing steps. They simply need to adhere to the following interface and that's it!

interface Renderer<T> {
  output: T; // Can be anything you want

  /** Reset the current instance */
  reset(): void;

  /** Called when an attribute is parsed */
  onProp(
    name: string,
    value: string | boolean | undefined | null,
    depth: number,
  ): void;

  /** Called at the start of each new vnode object */
  onOpenTag(
    name: string,
    hasChildren: boolean,
    isVoid: boolean,
    depth: number,
  ): void;

  /** Called when attribute parsing is done for the current vnode */
  onOpenTagClose(
    name: string,
    hasAttributes: boolean,
    isVoid: boolean,
    hasChildren: boolean,
    depth: number,
  ): void;

  /** Called when the node is a simple string */
  onTextNode(text: string, depth: number): void;

  /** Called when all children of the current vnode are parsed */
  onCloseTag(name: string, isVoid: boolean, depth: number): void;

  /** Called when vnode has it's own html (f.ex. jQuery plugins) */
  onDangerousInnerHTML(html: string): void;
}

License

MIT, see LICENSE.md.

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