cargo leptos 0.8.0-rc1

latest releases: 0.8.8, 0.8.7, 0.8.6...
4 months ago

Release notes copied from 0.8.0-alpha/beta. Changelog relative to 0.8.0-beta.

0.8 has been planned for a while, primarily to accommodate small changes that arose during the course of testing and adopting 0.7, most of which are technically semver-breaking but should not meaningfully affect user code.

If we don't hear any feedback about issues with this rc1 release, we will plan to release it as 0.8.0 in the next week or so.

Noteworthy features:

  • Axum 0.8 support. (This alone required a major version bump, as we reexport some Axum types.) (thanks to @sabify for the migration work here)
  • Significant improvements to compile times when using --cfg=erase_components, which is useful as a dev-mode optimization (thanks to @zakstucke) This is the default setting for debug mode in future releases of cargo-leptos, and can be set up manually for use with Trunk. (See docs here.)
  • Support for the new islands-router features that allow a client-side routing experience while using islands (see the islands_router example) (this one was me)
  • Improved server function error handling by allowing you to use any type that implements FromServerFnError rather than being constrained to use ServerFnError (see #3274). (Note: This will require changes if you're using a custom error type, but should be a better experience.) (thanks to @ryo33)
  • Support for creating WebSockets via server fns (thanks to @ealmloff)
  • Changes to make custom errors significantly more ergonomic when using server functions

As you can see this was a real team effort and, as always, I'm grateful for the contributions of everyone named above, and all those who made commits below.

WebSocket Example

The WebSocket support is particularly exciting, as it allows you to call server functions using the default Rust Stream trait from the futures crate, and have those streams send messages over websockets without you needing to know anything about that process. The API landed in a place that feels like a great extension of the "server function" abstraction in which you can make HTTP requests as if they were ordinary async calls. The websocket stuff doesn't integrate directly with Resources/SSR (which make more sense for one-shot things) but is really easy to use:

use server_fn::{codec::JsonEncoding, BoxedStream, ServerFnError, Websocket};

// The websocket protocol can be used on any server function that accepts and returns a [`BoxedStream`]
// with items that can be encoded by the input and output encoding generics.
//
// In this case, the input and output encodings are [`Json`] and [`Json`], respectively which requires
// the items to implement [`Serialize`] and [`Deserialize`].
#[server(protocol = Websocket<JsonEncoding, JsonEncoding>)]
async fn echo_websocket(
    input: BoxedStream<String, ServerFnError>,
) -> Result<BoxedStream<String, ServerFnError>, ServerFnError> {
    use futures::channel::mpsc;
    use futures::{SinkExt, StreamExt};
    let mut input = input; // FIXME :-) server fn fields should pass mut through to destructure

    // create a channel of outgoing websocket messages 
    // we'll return rx, so sending a message to tx will send a message to the client via the websocket
    let (mut tx, rx) = mpsc::channel(1);

    // spawn a task to listen to the input stream of messages coming in over the websocket 
    tokio::spawn(async move {
        while let Some(msg) = input.next().await {
            // do some work on each message, and then send our responses 
            tx.send(msg.map(|msg| msg.to_ascii_uppercase())).await;
        }
    });

    Ok(rx.into())
}

#[component]
pub fn App() -> impl IntoView {
    use futures::channel::mpsc;
    use futures::StreamExt;
    let (mut tx, rx) = mpsc::channel(1);
    let latest = RwSignal::new(None);

    // we'll only listen for websocket messages on the client
    if cfg!(feature = "hydrate") {
        spawn_local(async move {
            match echo_websocket(rx.into()).await {
                Ok(mut messages) => {
                    while let Some(msg) = messages.next().await {
                        latest.set(Some(msg));
                    }
                }
                Err(e) => leptos::logging::warn!("{e}"),
            }
        });
    }

    view! {
        <input type="text" on:input:target=move |ev| {
            tx.try_send(Ok(ev.target().value()));
        }/>
        <p>{latest}</p>
    }
}

What's Changed

  • Fix typo by @NCura in #3727
  • fix: matching optional params after an initial static param (closes #3730) by @gbj in #3732
  • docs: update example tailwind input css to v4 by @bimoadityar in #3702
  • More flexible server fn macro api by @ealmloff in #3725
  • fix(CI): switch to stable in semver for most compatibility by @sabify in #3737
  • fix(CI): cancel in-group inflight and pending jobs on new pushes in pull requests by @sabify in #3739
  • fix(CI): free-up disk, properly gate nightly feature and pre-install deps by @sabify in #3735
  • ArcLocalResource fix (0.8) by @zakstucke in #3741
  • ArcLocalResource fix (0.7) by @zakstucke in #3740
  • fix(CI): cleanup the directory no matter of the results by @sabify in #3743
  • fix(CI): sermver job name by @sabify in #3748
  • chore: no need to filter out "nightly" feature as of #3735 by @sabify in #3747
  • fix: use signals rather than Action::new_local() (closes #3746) by @gbj in #3749
  • feat: switch extract() helper to use ServerFnErrorErr (closes #3745) by @ilyvion in #3750
  • docs(Effect::watch): refer to dependency_fn and handler args by @jmevel in #3731
  • Leptos 0.8 by @gbj in #3529
  • chore: ensure WASM target is installed for examples with provided rust-toolchain.toml (closes #3717) by @gbj in #3752
  • Make trailing comma optional for either macro by @NCura in #3736
  • chore: add SignalSetter to prelude (closes #3547) by @gbj in #3753
  • fix: properly feature gating ui macro tests (Closes #3742) by @sabify in #3756
  • fix(CI): optimize CI workflow by @sabify in #3758
  • fix(CI): remove duplicate semver ci, #3758 follow-up by @sabify in #3764
  • fix(CI): install deps only if needed, speeds up CI by @sabify in #3768
  • fix: support IntoFragment for single element (closes #3757) by @gbj in #3759
  • fix: clippy errors by @sabify in #3772
  • fix(CI): install deno only if needed, #3768 follow-up by @sabify in #3773
  • fix(CI): remove caching by @sabify in #3776
  • fix(CI): conditional executions of only changed examples by @sabify in #3777
  • Make docs match reality by @ilyvion in #3775
  • fix(CI): toolchain will be determined and test against by CI by @sabify in #3778
  • Reduce use local signals for Action::new_local and similar primitives by @gbj in #3762
  • Tweaks to MaybeSendWrapperOption<_> by @gbj in #3781
  • fix: correctly handle optional parameters in ParentRoute by @gbj in #3784
  • fix: router example build process by @sabify in #3779
  • fix(CI): run only the exact examples on the only examples change by @sabify in #3782
  • Re-export the codee crate by @zakstucke in #3761
  • fix: allow repeated class= for all tuples, not only static ones (closes #3794) by @gbj in #3801
  • Fix Store notification order for nested keyed fields by @gbj in #3799
  • Improved handling of <Title/> by @gbj in #3793
  • derive_local for ArcSignal<T, LocalStorage> by @zakstucke in #3798
  • fix: portal example by @sabify in #3785
  • feat: add support for more HTTP methods in server fn codecs by @ChosunOne in #3797
  • Store test fixes by @gbj in #3803
  • Add track_caller to store field methods by @jvdwrf in #3805
  • fix: allow custom status codes or redirects for route fallbacks by @gbj in #3808
  • fix: Move several Into* trait impls for store fields out of stable module for wider use by @mahdi739 in #3807
  • fix: remove SendOption from public API of actions by @gbj in #3812
  • feat: support aliased Result return types for server_fn by @ifiokjr in #3755
  • Migrate from Tailwind 3 to Tailwind 4 for the axum example. by @pico-bolero in #3804
  • pass key reference to Selector::selected by @flisky in #3694
  • fix: correctly establish root ownership for static site generation (closes #3822) by @gbj in #3824
  • fix: do not match static segment with last character missing before slash (closes #3817) by @gbj in #3823
  • fix: prevent race condition in executor initialization + docs, optimization and tests by @sabify in #3802
  • chore: missing Copy/Clone impls for MappedSignal by @gbj in #3827
  • Revert "Remove getrandom (#3589)" by @ilyvion in #3830
  • Introducing cargo all-features clippy|nextest part of build process by @sabify in #3767
  • feat: allow using different error types for req/resp with WebSockets, closes #3724 by @myypo in #3766
  • feat: enhancing server_fn errors by @sabify in #3811

New Contributors

Full Changelog: 0.8.0-beta...v0.8.0-rc1

Don't miss a new leptos release

NewReleases is sending notifications on new releases.