brust — a Bun + Rust web framework: hyper serves the HTTP, Bun only wakes for your code #37029
Aitthi
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi 👋 — I've been building brust, a web framework with an unusual split: one Bun host process loads a napi
.nodethat contains the entire HTTP layer — a hyper 1.x server (HTTP/1.1 + HTTP/2, optional in-process TLS), routing, caches, and a template renderer, all pure Rust. Bun owns everything that's actually your code: routes, loaders, React SSR, and the client bundles.The trick: JSX compiles to templates
A route marked
native: truecompiles ahead of time — the JSX lowers into a MiniJinja template that Rust renders directly. At request time theloaderruns in a Bun worker to produce the context, and the HTML comes out of Rust. No React executes on the server for that page, and no JavaScript ships to the browser by default.LikeButtonrenders in Rust and itsbehaviorships as a small react-free chunk;CommentBoxis a real React island that hydrates when scrolled into view — and both write the samedefineStoreinstance, so they stay in sync with no event bus.Where Bun does the work
SharedArrayBuffer, and a worker holds several renders in flight (renderSlots) to overlap Suspense-bound requests instead of serializing them.Bun.buildproduces every client artifact — React island chunks and the react-free directive chunks — content-addressed, one chunk per component, loaded on demand.native: truepage is a Rust-side template render; the worker only wakes for the loader.brustjs devreloads by respawning the worker pool;brustjs build --ssgprerenders static routes to plain HTML.The payoff of the split: the hot path stays inside Rust, and Bun only wakes for application code — benchmarks and methodology live in
bench/RESULTS.mdif you're curious.Links
Fair warning, it's
0.1.x-alphaand APIs still move. Happy to answer anything about the napi crossing or the JSX→template compiler.All reactions