Universal React in OCaml
summary
server-reason-react implements react-dom/server in OCaml to natively render HTML for Reason React apps and enable one shared component compiled to JS or OCaml, letting Ahrefs migrate ~2,000 files to server rendering. The project reimplements three server render functions, adds a browser-only PPX and switch_platform support to swap client/server implementations, embeds QuickJS for regex parity, and reports microbenchmarks showing up to ~34× speedups against older Node/Bun baselines. Future work targets server components and a lightweight meta-framework.
AI-written summary · about
chapters (20)
- 0:00Introduction and background
- 1:46What is React and ReasonReact
- 2:48Client vs server rendering
- 4:30Benefits of server rendering
- 5:56Reimplementing React for server
- 6:38Universal React components
- 8:03Performance benefits of OCaml
- 9:31Challenges with universal code
- 11:38Binding browser APIs
- 13:01URL and regex in universal code
- 15:11Reimplementing regex engine
- 17:19Using QuickJS for regex
- 18:01Migration progress and results
- 18:23Creating new ecosystem tools
- 19:48Future: Server-side components
- 20:32Future: Meta framework
- 21:12Q&A: Library differences
- 23:42Q&A: User experience and trade-offs
- 24:04Q&A: JavaScript engine dream
- 24:48Q&A: Developer experience evolution
