Jane Street's Bonsai: A UI Library That Treats State Like LEGO
Bonsai: Janestreet's UI Library

Jane Street's Bonsai is a UI library for building reactive web apps in OCaml, used internally for everything from corporate directories to trading tools. Unlike frameworks that fuse state, incrementality, and rendering into one component, Bonsai lets you compose these primitives a la carte. This separation enables efficient incremental updates and flexible state management, even for complex scenarios like tabbed interfaces. Built on OCaml, it allows sharing types and logic between backend and frontend, and comes with a powerful templating language and expressive testing tools.
The same primitives that prevent re-rendering the entire page during user interaction can also be used to incrementalize an expensive business logic computation on a live-updating dataset.
- flufluflufluffy
> And because Bonsai is written in OCaml, it becomes possible to use the same language and types on both the backend and frontend.
Finally! I was waiting for this to become possible!
- bsmith89
There's a great Signals and Threads (Jane Street's Podcast) episode about this work: https://signalsandthreads.com/building-a-ui-framework/
- chrischen
Curious how this compares to Melange which is used by Ocaml shops as well to double up on Ocaml for both front and backend (ahrefs being the major user and sponsor). Does this mean giving up a lot of the JS ecosystem (React, graphql, etc)?
- rw2
I am sure it's very performant, but to me it's extremely ugly; Surely someone can fix margins and still have it be performant.
- cachius
What does JaneStreet do besides sponsoring nerdy Youtube channels and writing UI libraries?
- user2342
Interesting! What are Bonsai's dependencies? I use OCaml but - so far - none of Janestreets libraries etc.
- Schlagbohrer
Can someone who understands web UI programming tell me if this would be good for my local agent to use to produce HTML based reports and outputs for me? Or for TUI outputs?
- xvilka
Looks like it's Web-only, no mention of the native UI support (terminal UI excluded).