Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Native implementation of React's Server-side rendering (SSR) and React Server Components (RSC) architecture for Reason and OCaml

License

NotificationsYou must be signed in to change notification settings

ml-in-barcelona/server-reason-react

Repository files navigation

Native implementation of React's server-side rendering (SSR) and React Server Components (RSC) architecture for Reason.

Designed to be used withreason-react andMelange. Together it enables developers to write efficient React components using a single language, while target both native executable and JavaScript.

Features

  • Server-side rendering HTML withReactDOM.renderToString/ReactDOM.renderToStaticMarkup
  • Server-side renderingstreaming HTML withReactDOM.renderToStream (similar to react@18renderToReadableStream)
  • IncludesReact.Suspense andReact.use() implementations
  • server-reason-react-ppx - A ppx transformation to support JSX on native
  • Allreason-react interface is either implemented or stubbed (some of the methods, like React.useState need to be stubbed because they aren't used on the server!)
  • React Server Components - A ReactServerDOM module for streaming RSC payload, an esbuild plugin to enhance the bundle with client-components mappings, a Dream middleware to serve the RSC endpoint and a dummy implementation of a router (stillwork in progress)

Warning: This repo contains a few parts that are considered experimental and there's no guarantee of stability. Most of the stable parts are used in production at ahrefs.com, app.ahrefs.com and wordcount.com. Check each module's documentation for more details.

Why

There are plenty of motives for it, the main one is thatahrefs (the company I work for) needs it. We use OCaml for the backend and Reason (with React) for the frontend. We wanted to take advantage of the same features from React.js in the server as well.

Currently 100% of the public site (ahrefs.com), the shell part of the dashboard (app.ahrefs.com) andwordcount.com are rendered on the server withserver-reason-react.

What made us create this library was mostly:

  • Use the same language (Reason) for both server and client
  • Embrace server-client integrations such as type-safe routing, JSON decoding/encoding, sharing types and logic, while keep enjoying functional programming patterns
  • Native performance is better than JavaScript performance (Node.js, Bun, Deno)
  • Writing React from a different language than JavaScript, but still using the brilliant pieces from the ecosystem
  • Exploration of OCaml effects and React
  • Further exploration with OCaml multicore, direct-style and concurrency with React features such as async components, React.use or Suspense

Explained more about the motivation inthis blog post and also in my talk aboutUniversal react in OCaml at fun-ocaml 2024 andServer side rendering React natively with Reason at ReactAlicante 2023

Other libraries inside this repo

Aside from the core (React,ReactDOM andReactServerDOM), server-reason-react repo contains some common melange libraries to ensure components are universal. Some of them are reimplementations in native of those libraries, and others are new implementations. Currently they are part of the repository, but eventually will be moved out to their own opam packages and repositories.

NameDescriptionMelange equivalent library
server-reason-react.browser_ppxA ppx to discard code for each platform with different attributes:let%browser_only,switch%platform and@platform
server-reason-react.url_js andserver-reason-react.url_nativeUniversal URL module: binds towindow.URL in browser, implemented withopam-uri in native
server-reason-react.melange_ppxA ppx to add the melange attributes to native codemelange.ppx
server-reason-react.promiseVendored version ofaantron/promise with melange supportPR#80promise
server-reason-react.beltImplementation of Belt for nativeAPI referencemelange.belt
server-reason-react.jsImplementation ofJs library for native (unsafe/incomplete). Check the issue#110 for more detailsmelange.js
server-reason-react.fetchStub of fetch with browser_ppx to compile in nativemelange.fetch
server-reason-react.webapiStub version of Webapi library for native code compilationmelange-webapi
server-reason-react.domStub version of Dom library for native code compilationmelange-dom

Thedocumentation site is generated with odoc and hosted on GitHub Pages.

Demo

Thedemo folder contains a bunch of demos under a server to showcases the usages ofserver-reason-react. Check theREADME for how to setup and run it.

Want to contribute?

DM me

About

Native implementation of React's Server-side rendering (SSR) and React Server Components (RSC) architecture for Reason and OCaml

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors5


    [8]ページ先頭

    ©2009-2025 Movatter.jp