Skip to content

vs SPA + API / Rust front-end frameworks ​

These render in a completely different place: an SPA hands the UI to a client framework (React / Vue / Svelte), and Leptos, Dioxus and Yew write the UI in Rust and compile it to WASM; this runtime keeps the UI in server templates.

What a traditional SPA + API needs ​

A "save customer" button:

Back end: route → handler → validation → JSON serialization
Front end: API client → call → check the status → draw field errors on 422 → notice on 403 →
           ask to reload on 409 → error card on 500 → refetch the list on success → loading state

The second half is rewritten for every module. With this runtime:

rust
"create" => {
    let user = User::find_or_fail(context.user.parse::<i64>()?).await?;
    if !may_create_customer(&user) {
        return Ok(LinkerResponse::policy(messages::POLICY));
    }

    let name = text(&args, "name");
    if name.is_empty() || name.chars().count() > 80 {
        return Ok(LinkerResponse::validation([("name", "A name is required, at most 80 characters.")]));
    }
    create!(Customer { name: &name }).await?;

    Ok(LinkerResponse::ok()
        .then(Action::toast("success", "Created"))
        .then(Action::render_fragment("#list", "customers", json!({}))))
}
html
{{ cg_button("Create", attrs={"data-linker-call": "create", "data-linker-args": "form"}) }}

The runtime does that whole front-end list in one place: field errors, permission notices, expiry notices, redrawing the list.

(may_create_customer and text() are illustrative; how to write authorization and validation is in Access control.)

Compared ​

SPA + APILeptos / DioxusThis runtime
RoutingClient + API routesShared Rust routesServer; interaction needs no new routes
UI languageTS / JSRust (compiled to WASM)MiniJinja templates + Rust builders
Data contractAPI schema (JSON)Server function typesValidation in call + data
Error handlingDIYDIYFixed kinds, one handler in the browser
Bundle sizeFramework + every page componentA WASM file (commonly hundreds of KB)Core modules + the components used, loaded on demand
First loadWaits for JSSSR, then hydrationServer HTML, usable immediately
Highly interactive UI (drag and drop, canvas, live editing)Good at itGood at itNot good at it
Offline / PWAGood at itPossibleNot supported

Mixing ​

You don't have to pick one. Highly interactive regions (a canvas, drag-and-drop sorting) can be standalone front-end components or WASM islands, while the rest of the page uses Linker:

  • When a front-end component needs to call the server, it can still use the Linker endpoint and get the same error shapes.
  • The PHP version's charts work this way: the browser draws, the data comes through Linker. The Rust version hasn't ported the chart component yet, but the runtime's JS is already here (see Sync).

When to choose an SPA or a Rust front-end framework ​

  • The product itself is a highly interactive application.
  • You need offline support, push, local data.
  • Front-end and back-end teams are separate, and the API serves several clients (mobile apps) anyway.
  • You want to share Rust types between front end and back end, and accept WASM's build and size costs → Leptos / Dioxus.