cargo leptos 0.6.1

latest releases: 0.7.0-rc1, 0.7.0-rc0, 0.7.0-preview2...
9 months ago

This is release for our new server functions rewrite and Axum 0.7 support.
This should be a relatively feature-rich release, with limited breaking changes.

Migration

Actix

  • You can remove any explicit .handle_server_fns() call in your main.rs, as server functions are now handled in .leptos_routes()
  • The current extract function has been removed, and replaced with a new extract that has the same API as the current extractor. I think this API is strictly better, but please share feedback if you disagree.

Axum

  • This release supports Axum 0.7, so you'll need to migrate from Axum 0.6. The easiest way to do this is probably to consult the diff on one of the examples.
  • You can remove any explicit .handle_server_fns() call in your main.rs, as server functions are now handled in .leptos_routes()
  • The current extract function has been removed, and replaced with a new extract that has the same API as the current extractor. I think this API is strictly better, but please share feedback if you disagree.
  • RequestParts has been removed, as http::request::Parts now implements Clone: any use_context::<RequestParts>() should be updated to use Parts directly instead.

ServerFnError::new()

The addition of custom error types means that constructing ServerFnError inside server functions can cause type inference errors:

let oops = Err(ServerFnError::ServerError("No server state".to_string()));
return oops;  // this is fine
oops? // this is not: cannot infer type of the type parameter `E` declared on the enum `ServerFnError`

As a result, we've added a helper ServerFnError::new which simply constructs a ServerFnError::<NoCustomError>::ServerError:

let oops = Err(ServerFnError::new("No server state"));
return oops;  // this is fine
oops? // this is also fine now

This has the benefit of being more concise than the earlier pattern in any case.

Features

A rewritten server function system that is backwards-compatible, but reduces binary size and increases flexibility, specifically by allowing

  • automatic setup of server fn handlers with .leptos_routes() from the integrations
  • a variety of additional built-in encodings (rkyv, multipart forms/file uploads) in addition to the current set (GET URL, POST URL, CBOR, Rkyv) (#1868, #1989)
  • support for streaming responses from server functions (#1284)
  • ability to create custom user encodings for input and output by deriving IntoReq, FromReq, IntoRes, and/or FromRes traits
  • ability to mix and match encodings easily: This server function should be a JSON POST request and a ByteStream response, this one should be GET URL request and an rkyv response, etc.; any combination of the encodings above is supported
  • custom error types (#1657)
  • a #[middleware] macro to add per-server-function middleware from the Tower or Actix ecosystems (#1461)

Note: The additional included encodings (serde_lite, rkyv, multipart form data) are all enabled by additive features on the server_fn crate. If you want to use them you can just add that crate as a dependency and enable the required features.

Example: You can find a comprehensive example of these new features in the new server_fns_axum example.

Full Changelog: v0.5.6...v0.6.1

Don't miss a new leptos release

NewReleases is sending notifications on new releases.