RFD 139: Browser UIs in Rust with Leptos
DiscussionDecision2026-11-18Jean Mertz
Required byRFD 140
Summary
JP's browser UIs are written in Rust, compiled to WebAssembly, and rendered on the client with Leptos. Each command plugin embeds its compiled UI bundle in its binary and serves it alongside its JSON API, adding no handwritten JavaScript to the repository.
Context
JP has three browser-facing surfaces:
jp-vite's documentation site, a VitePress and Vue application whose files are synced into each workspace that uses it.jp serve web, a prototype that renders HTML on the server with maud and runs handwritten JavaScript checked byjust typecheck-js; it is scheduled for a rewrite.jp review serve, a local JSON API whose browser frontend RFD 136 deferred.
jp-vite remains on VitePress and Vue, but new browser UIs will not add more JavaScript to the repository.
The review frontend requires client-side behavior that server rendering cannot replace:
- Mapping DOM text selections to source byte offsets through the
data-sanddata-espans emitted bymd-html(RFD 124). - Highlighting commented ranges without mutating the rendered DOM, using the CSS Custom Highlight API.
- Updating comment threads in place as the assistant replies during a pass.
The workspace already carries the core WebAssembly bindings (wasm-bindgen, js-sys, and web-sys) as transitive dependencies in Cargo.lock, and the API payloads exchanged with the server are already defined as Rust structs.
Decision
Stack
Browser UIs are written in Rust, compiled for wasm32-unknown-unknown, and rendered in the browser with Leptos (pinned to 0.9.0-rc1 until 0.9.0 is released).
Rendering is strictly client-side. The plugin serves a static HTML shell, the compiled WebAssembly bundle, and the JSON API that the client calls. There is no server-side rendering or hydration, and the server crate does not depend on Leptos.
Views use Leptos's builder syntax rather than the view! macro, following Leptos's counter_without_macros example:
div().child((
button()
.on(ev::click, move |_| count.update(|n| *n += 1))
.child("+1"),
span().child(move || count.get()),
))Builder syntax is standard Rust: rustfmt formats it, rust-analyzer completes it, and clippy lints it without macro-expansion indirection or leptosfmt.
The repository contains no JavaScript source files for these UIs. At build time, wasm-bindgen generates the JS glue module, and the HTML shell loads it with a one-line <script type="module">. Browser APIs that web-sys gates behind web_sys_unstable_apis (such as the CSS Custom Highlight API) are bound directly in Rust with small #[wasm_bindgen] extern blocks.
Crates
A plugin with a browser UI adds two sibling crates to the workspace:
| Crate | Target | Role |
|---|---|---|
<plugin>/api (jp-<plugin>-api) | host and wasm32 | Request and response types for the JSON API (serde, no I/O). |
<plugin>/ui (jp-<plugin>-ui) | host and wasm32 | Client-side Leptos UI. |
Because the server serializes and the UI deserializes the same api types, wire-format changes cannot silently drift between server and client. Renaming a field or adding an enum variant that an exhaustive match does not handle fails compilation immediately. Semantic changes and newly added optional fields are covered by tests: unit tests in the api crate pin the serialized JSON representation of each type, and endpoint tests in the server crate verify behavior (such as default anchor versions).
The ui crate keeps domain and layout logic in pure functions over owned types (mapping selections to byte ranges, positioning comment cards, and scheduling polls) while keeping reactive components and DOM bindings thin. Because ui also compiles on the host target, cargo check, clippy, rustqual, rust-analyzer, and cargo test check it alongside the rest of the workspace.
Testing
- Pure UI logic is unit-tested on the host in
_tests.rsfiles, matching the rest of the workspace. - DOM interactions and mounted components are tested with
wasm-bindgen-testconfigured withrun_in_browser, running inside a headless browser viawasm-bindgen-test-runner.
Building and embedding
rust-toolchain.tomlincludes thewasm32-unknown-unknowntarget.just build-ui <plugin>compiles theuicrate forwasm32-unknown-unknownusing a size-optimizedwasm-releaseprofile, runswasm-bindgen --target webintotarget/ui/<plugin>/, and copies the UI's stylesheet into that directory. The recipe installs thewasm-bindgenCLI at the exact version pinned for thewasm-bindgencrate inCargo.lock, because the CLI rejects modules compiled against a mismatched crate version.- When
JP_<PLUGIN>_UI(e.g.JP_REVIEW_UI) is set at compile time, the plugin'sbuild.rsembeds the bundle from that directory; if the directory does not contain a valid bundle,build.rsfails the build rather than falling back. WhenJP_<PLUGIN>_UIis unset,build.rsembeds a placeholder HTML page explaining how to build the UI.build.rsnever invokescargo. just install-plugin <plugin>runsjust build-ui <plugin>before installing any plugin that has auicrate. Runningcargo installdirectly installs the plugin binary with the JSON API and the placeholder page.- While local or Git installs without
JP_<PLUGIN>_UImay serve the placeholder page, published plugin binaries must embed the bundle built from the same revision: release builds setJP_<PLUGIN>_UIand fail if the bundle is missing.just plugin-buildwill be updated to build and pass the bundle when the first published plugin gains auicrate.
Tooling for the assistant
The workspace's cargo_check and cargo_test tools already gate optional verification passes behind tool options (wiki_check, qual_check, site_check). This RFD adds two options for WebAssembly crates:
wasm_checkoncargo_checkrunsclippyforwasm32-unknown-unknownon every browser crate.wasm_testoncargo_testruns the headless-browser test suite for every browser crate.
Browser crates declare themselves in Cargo.toml, where the tools, just, and CI discover them via cargo metadata:
[package.metadata.jp]
wasm = trueA web-development skill enables both options and documents the conventions from this RFD. A web-dev persona layers that skill on top of dev (paralleling app-dev for the macOS app), while other personas skip wasm32 builds.
CI
A path-filtered web GitHub Actions workflow (modeled on app.yml) runs whenever a browser crate, an api crate, md-html, Cargo.lock, or rust-toolchain.toml changes. It runs clippy on all browser crates for wasm32-unknown-unknown, executes their browser tests in headless Chrome via ChromeDriver, and builds every UI bundle.
Consequences
Benefits:
- A single language and toolchain from on-disk storage to the browser DOM.
- Compile-time verification that client code matches the server's request and response types.
- Host-side unit tests and lints run on UI logic with the workspace's standard Rust tooling.
- A settled, JavaScript-free architecture for rewriting
jp serve web.
Costs:
- Building a full plugin UI requires a
wasm-bindgenpost-processing step and thewasm32-unknown-unknowntarget outside a plaincargo build. - Installing a plugin with plain
cargo install(without building the bundle first) serves the placeholder page instead of the UI. - Leptos and its dependency tree must be audited in
cargo-vetandcargo-denyand are compiled during host workspace builds. - Leptos
0.9.0-rc1is a pre-release dependency whose API may change before0.9.0. - Target-specific
wasm32build failures are caught only under theweb-devpersona or in CI, matching the tradeoff for the macOS app. - WebAssembly bundles are larger than minimal handwritten scripts, though bundle size is negligible for a local loopback server.
Alternatives
- Server-rendered HTML with small scripts (as in
jp serve web). Mapping selections to source byte offsets and rendering CSS custom highlights still require client-side code, and server rendering forces the plugin to maintain an HTML view layer alongside its JSON API. - Server-rendered HTML with WebAssembly islands for selection handling. Splits the UI across two rendering models and requires full-page or fragment reloads to reflect live state changes.
- Vue components inside
jp-vite. Adds more JavaScript and couples a command plugin's UI to the documentation site's sync and release cycle. - Other Rust UI frameworks. Dioxus relies on its own
dxbuild CLI; Yew uses a virtual DOM and sees less active development; Sycamore offers fine-grained reactivity similar to Leptos but with a smaller ecosystem. - Leptos's
view!macro. More concise than builder syntax, but requiresleptosfmtalongsiderustfmtand produces diagnostics that point into macro expansions. - Trunk or
cargo-leptos. Both tools download externalwasm-bindgenandwasm-optbinaries during builds, whereas JP's client-only bundles require onlycargo buildandwasm-bindgen. - Compiling the WebAssembly bundle inside
build.rs. Would allow a plaincargo installto embed the UI, but still requires an externalwasm-bindgenbinary (or compilingwasm-bindgen-cli-supportinto every build script) and spawns nestedcargoinvocations that inherit hostclippyor coverage flags. - Restricting the
uicrate tocfg(target_arch = "wasm32"). Avoids compiling Leptos on the host, but preventsrust-analyzerand default host checks from inspecting UI components, allowingapichanges that break the UI to pass outsideweb-dev.
Risks and Open Questions
- Host compilation overhead. This design assumes Leptos compiles cleanly on the host target without significant overhead. If host compilation fails or adds more than roughly 10% to a cold
cargo check --workspace, component modules inuicrates will be gated behind#[cfg(target_arch = "wasm32")]. rustqualtest recognition.rustqualmay not recognize#[wasm_bindgen_test]functions as tests and could flag UI components as untested; if so,qualshould be updated rather than adding suppression markers.nextestintegration.cargo_testusescargo nextest; ifnextestcannot drivewasm-bindgen-test-runner,wasm_testwill invokecargo test --target wasm32-unknown-unknowndirectly.- Local WebDriver availability. Running browser tests locally requires
chromedriveronPATH(or runningsafaridriver --enableonce on macOS). - Leptos
0.9.0-rc1stability. Minor API adjustments may be required when upgrading to the final0.9.0release.
Implementation Plan
A single phase, landing alongside the first plugin browser UI (RFD 140):
- Add
wasm32-unknown-unknowntorust-toolchain.toml, configure thewasm-releaseprofile, add workspace glob patterns for*/apiand*/ui, and addjust build-uiand bundle building injust install-plugin. - Add
wasm_checkandwasm_testtocargo_checkandcargo_test, and create theweb-developmentskill andweb-devpersona. - Add the path-filtered
webCI workflow. - Add
cargo-vetandcargo-denyentries for Leptos and its dependencies.
Release builds remain unchanged until a published plugin gains a ui crate (see Building and embedding).