Native implementation of React's server-side rendering (SSR) and React Server Components (RSC) architecture for Reason.
Designed to be used with reason-react and Melange. Together it enables developers to write efficient React components using a single language, while target both native executable and JavaScript.
ReactDOM.renderToString/ReactDOM.renderToStaticMarkupReactDOM.renderToStream (similar to react@18 renderToReadableStream)React.Suspense and React.use() implementationsThere are plenty of motives for it, the main one is that ahrefs (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) and wordcount.com are rendered on the server with server-reason-react.
What made us create this library was mostly:
Explained more about the motivation in this blog post and also in my talk about Universal react in OCaml at fun-ocaml 2024 and Server side rendering React natively with Reason at ReactAlicante 2023
Aside from the core (React, ReactDOM and ReactServerDOM), 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.
Name | Description | Melange equivalent library |
|---|---|---|
A ppx to discard code for each platform with different attributes: | ||
| Universal URL module: binds to | |
A ppx to add the melange attributes to native code | ||
| Vendored version of aantron/promise with melange support PR#80 | |
| Implementation of Belt for native API reference | |
| Implementation of | |
| Stub of fetch with browser_ppx to compile in native | |
| Stub version of Webapi library for native code compilation | |
| Stub version of Dom library for native code compilation |
The documentation site is generated with odoc and hosted on GitHub Pages.
The demo folder contains a bunch of demos under a server to showcases the usages of server-reason-react. Check the README for how to setup and run it.