Client-Side Apps in Rust
A while back I wrote about why I hate JavaScript — specifically, that TypeScript's types don't exist once your program is actually running, so a JSON.parse result gets cast, not checked. That post ended with a pointer to Rust compiled to WebAssembly as the alternative. This one is the follow-through: the actual case for writing client-side, single-page-application code in Rust instead of JavaScript or TypeScript.
One scoping note before I start: this is specifically about the client. Whether the server behind it happens to be written in Rust too, and whether you're using server-side rendering, is beside the point — that's a separate discussion. This is about what runs in the browser, in the tab, talking to whatever server is on the other end of a fetch.
1. Type safety doesn't stop at the network boundary
The JSON problem from my last post isn't a server-side thing — it's a client-side thing, because the client is where you're calling fetch and parsing what comes back. In TypeScript, that response is unknown wearing a cast. In Rust, deserializing with serde either gives you the typed value or an Err — at the parse boundary, before the bad data touches your UI code. Same argument, same example, just happening in the browser tab instead of a Node server. I won't re-run the Invoice.issuedAt example again here; go read the original if you want the full version.
2. Room to actually compute things
JavaScript engines are remarkable pieces of engineering, but they're still doing dynamic-type dispatch and JIT warm-up on every hot path, and a lot of real client-side work — parsing a large payload, doing layout math, running a filter/sort/aggregate over a big in-memory dataset, canvas or image manipulation — is exactly the kind of workload that benefits from code that's compiled ahead of time with known types and no runtime type checks in the loop. WASM doesn't make everything faster automatically, but it removes an entire category of overhead JS can't opt out of. If your SPA does more than render forms and call APIs, that headroom starts to matter.
3. Lower memory use over a long-lived session
SPAs are increasingly the kind of app people leave open in a tab for a whole workday, not a page they load and discard. JavaScript's garbage collector is good, but it's still a garbage collector: allocations pile up, objects get boxed, "hidden classes" churn as object shapes shift, and none of that goes away just because your tab has been idle. A Rust/WASM client has none of that — no GC pauses to schedule around, no background collector doing surprise work, and a much smaller, more predictable memory footprint that doesn't creep upward the longer the tab stays open.
4. Result and Option instead of hoping you remembered try/catch
Error handling in JS is opt-in by construction — a throw propagates until something catches it, or it doesn't, and async functions add their own footguns around forgetting await. Rust makes handling explicit and checked: a function that can fail returns Result<T, E>, and the compiler will not let you silently ignore the error case the way a missing catch block lets you. It's not that Rust prevents failure — it's that failure has to be acknowledged in the type signature and handled at the call site, instead of being an implicit possibility hanging off of every function call in the codebase.
5. No more "which kind of nothing is this"
My last post complained about JavaScript having two ways to mean nothing — null and undefined — and TypeScript spending a whole feature area (strictNullChecks, ??, ?.) just taming that. Rust doesn't have null pointers at all. Absence is Option<T>, a real value the compiler forces you to handle before you can get at what's inside. Whole categories of "cannot read properties of undefined" bugs simply don't compile.
The frameworks are actually good now
This isn't a theoretical exercise — the tooling has caught up. Leptos, Dioxus, and Yew are all mature enough to build real, shipped products with. This site itself is Leptos, server-rendered. For a client-heavier example, competition.zoptiq.no is Dioxus — and it's not some bare-bones proof of concept either: it mixes in "cute" JS-powered animation (curtains.js, a WebGL canvas library) right alongside the Rust/WASM app, which is the point I'd make to anyone worried that choosing Rust locks you out of the JS ecosystem's more polished visual libraries. It doesn't. You can have both.
Both of those sites also happen to use Tailwind — one of the most widely used CSS frameworks around — as first-class, zero-Node tooling: cargo-leptos and the Dioxus CLI (dx) both auto-detect a tailwind.css and handle the build themselves. The usual "yes, but the frontend tooling chain" objection doesn't really hold up here; it's genuinely no more setup than in a JS project, often less.
None of this means JavaScript is going away, or that you're wrong for reaching for React tomorrow morning — the ecosystem is bigger, the hiring pool is bigger, and "easier to start" is a real advantage I'm not pretending away. But if you're building something that has to stay correct and responsive for hours at a time, and you're willing to trade a steeper first few weeks for a client that actually holds the guarantees it claims to make, Rust in the browser isn't a novelty anymore. It's just a good option.
Comments
Log in to leave a comment.