Jane Street open-sources Bonsai, its OCaml framework for reactive web apps
Bonsai is the UI library Jane Street uses to build nearly all of its internal web tooling, from the corporate directory to interfaces that monitor live trading systems. Written in OCaml and drawing on ideas from Elm, it models components as purely functional, composable state machines and renders incrementally—recomputing a value only when the state it depends on actually changes. That incrementality applies to everything, not just the view, so the same primitives that avoid re-rendering the page can also short-circuit an expensive business-logic calculation running over a live dataset.
The design deliberately splits apart concerns that most frameworks bundle into a single component abstraction: state, incrementality, and rendering are separate primitives you compose as needed, with state managed outside the component hierarchy rather than hoisted through it. Because both frontend and backend are written in OCaml, teams can share types and business logic across the stack—a practical win Jane Street credits for letting it port terminal-only internal tools to the web. The framework also ships a templating language, per-component stylesheets, and an expect-test system that manipulates the DOM programmatically and asserts on rendered diffs, letting developers test full components without a browser.
Underneath the web-specific layer, the core Bonsai library is a general engine for incremental, composable state machines. Bonsai_web specializes it for browsers, Bonsai_term targets terminal UIs, and an April Fools’ prototype, Bonsai_vr, extended the same reactive model to virtual reality—underscoring that the abstraction isn’t tied to any single rendering target.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.