Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork13
Native implementation of React's Server-side rendering (SSR) and React Server Components (RSC) architecture for Reason and OCaml
License
ml-in-barcelona/server-reason-react
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
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.
- Server-side rendering HTML with
ReactDOM.renderToString/ReactDOM.renderToStaticMarkup - Server-side renderingstreaming HTML with
ReactDOM.renderToStream(similar to react@18renderToReadableStream) - Includes
React.SuspenseandReact.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.
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
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.
| Name | Description | Melange equivalent library |
|---|---|---|
server-reason-react.browser_ppx | A 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_native | Universal URL module: binds towindow.URL in browser, implemented withopam-uri in native | |
server-reason-react.melange_ppx | A ppx to add the melange attributes to native code | melange.ppx |
server-reason-react.promise | Vendored version ofaantron/promise with melange supportPR#80 | promise |
server-reason-react.belt | Implementation of Belt for nativeAPI reference | melange.belt |
server-reason-react.js | Implementation ofJs library for native (unsafe/incomplete). Check the issue#110 for more details | melange.js |
server-reason-react.fetch | Stub of fetch with browser_ppx to compile in native | melange.fetch |
server-reason-react.webapi | Stub version of Webapi library for native code compilation | melange-webapi |
server-reason-react.dom | Stub version of Dom library for native code compilation | melange-dom |
Thedocumentation site is generated with odoc and hosted on GitHub Pages.
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.
About
Native implementation of React's Server-side rendering (SSR) and React Server Components (RSC) architecture for Reason and OCaml
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.