cargo leptos 0.5.2
v0.5.2

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

This has a bunch of bugfixes, small docs improvements, etc. but there are actually a bunch of cool new features, mostly from our growing body of contributors. See the full changelog below, but here are some highlights (apologies if I missed anything big)

Features

extractor() function with better API

The extract API is awkward due to closure. This adds an extractor function which is a little more ergonomic.

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Search {
    q: String,
}

// Actix
#[server]
pub async fn query_extract() -> Result<Search, ServerFnError> {
    use actix_web::web::Query;
    use leptos_actix::extractor;

    let Query(query) = extractor().await?;
    Ok(query)
}

// Axum
#[server]
pub async fn data() -> Result<Search, ServerFnError> {
    use axum::extract::Query;
    use leptos_axum::extractor;
    
    let Query(query) = extractor().await?;
    Ok(query)
}

<Portal/>

Adds a portal component that lets you render some view mounted in a location other than where it appears in the view tree.

<Show when=show_overlay fallback=|| ()>
    <div>Show</div>
    <Portal mount=document().get_element_by_id("app").unwrap()>
        <div style="position: fixed; z-index: 10; width: 100vw; height: 100vh; top: 0; left: 0; background: rgba(0, 0, 0, 0.8); color: white;">
            <p>This is in the body element</p>
            <button id="btn-hide" on:click=move |_| set_show_overlay(false)>
                Close Overlay
            </button>
            <button id="btn-toggle" on:click=move |_| set_show_inside_overlay(!show_inside_overlay())>
                Toggle inner
            </button>

            <Show when=show_inside_overlay fallback=|| view! { "Hidden" }>
                Visible
            </Show>
        </div>
    </Portal>
</Show>

Server Function Named Arguments

Now that we've made all server function arguments optional, this adds in the ability to pass in one or more named arguments:

#[server(endpoint = "/path/to/my/endpoint")]
pub async fn my_server_action() -> Result<(), ServerFnError> {
    Ok(())
}

#[server(encoding = "GetJson")]
pub async fn my_server_action() -> Result<(), ServerFnError> {
    Ok(())
}

Directives

Adds support for directive functions, which can be used with use: in the view:

// This doesn't take an attribute value
fn my_directive(el: HtmlElement<AnyElement>) {
    // do sth
}

// This requires an attribute value
fn another_directive(el: HtmlElement<AnyElement>, params: i32) {
    // do sth
}

// ... in the view
view! {
  <div use:my_directive></div>
  <SomeComponent use:another_directive=5 />
}

slice!() macro

Makes it easier to define slices. Expands to the same output as create_slice:

#[derive(Default)]
pub struct Inner {
    inner_count: i32,
    inner_name: String,
}

let outer_signal = create_rw_signal(Outer::default());

let (count, set_count) = slice!(outer_signal.count);

What's Changed

  • docs: clarify what "once per signal change" means by @arcstur in #1858
  • fix: documentation in leptos_reactive::Trigger by @hiraginoyuki in #1844
  • feat: add extractor functions with better API than extract by @gbj in #1859
  • docs: add islands guide/demo to the docs by @gbj in #1861
  • Remove extra "```rust" and add closing bracket to Testing docs by @he00741098 in #1870
  • fix: Add missing argument name to WrapsChildren component in section 3.9 of the book by @johnnynotsolucky in #1866
  • fix: Prop-drilling example in Parent-Child Communication section of the book by @johnnynotsolucky in #1865
  • Fix: use placeholder in comments for empty component names by @flosse in #1850
  • Portal by @maccesch in #1820
  • Improvements for the book - Issue #1845 by @obioma in #1856
  • fix: hydration ID clash with Suspense > Outlet > Suspense (closes #1863) by @gbj in #1864
  • fix: correctly untrack in .try_with_untracked (closes #1880) by @gbj in #1881
  • feat: Implement Default trait for RwSignal and StoredValue by @luoxiaozero in #1877
  • fix munged markdown by @dandante in #1873
  • docs: add some missing #[must_use] to avoid accidental () rendering by @gbj in #1885
  • Fix failing cargo make lint for hackernews_js_fetch by @gbj in #1887
  • feat: add reasonable fallback behavior for ActionForm in an island by @gbj in #1888
  • fix: ensure there's no reactive tracking in an on_cleanup (closes #1882) by @gbj in #1889
  • Custom attributes on head tags by @ymijorski in #1874
  • refactor: tailwind examples by @azzamsa in #1875
  • fix: properly handle trailing / in splat routes (closes #1764) by @gbj in #1890
  • docs: update Dockerfile in deployment.md to work with cargo-leptos@0.2.0 by @quanhua92 in #1898
  • feat: add new method to NodeRef by @tqwewe in #1896
  • fix: bug with client-side routing no longer working due to different origin by @gbj in #1899
  • Remove Clone requirement on SignalWith for Resource by @Xendergo in #1895
  • chore: tweak tracing levels by @gbj in #1901
  • fix: properly handle trailing / in more routes by @PianoPrinter in #1900
  • feat(router): Add the target attribute to the A component by @luoxiaozero in #1906
  • fix: maintain hash when setting query signal (closes #1902) by @gbj in #1908
  • docs: fix typo by @saikatdas0790 in #1910
  • fix: try_update() and try_set() on Resource should not panic (closes #1915) by @gbj in #1916
  • feat: optional named arguments for #[server] macro (closes #1621) by @safx in #1904
  • feat: directives by @maccesch in #1821
  • fix: router should still scroll to hash even if path didn't change (closes #1907) by @gbj in #1917
  • docs: better document default and wasm features on leptos_axum (closes #1872) by @gbj in #1883
  • docs: add chapter on nested reactivity and iteration by @gbj in #1920
  • chore: please clippy by @gbj in #1924
  • feat: Add local attribute for Await by @kerkmann in #1922
  • Clippy: use .first() [not .get(0)] by @martinfrances107 in #1929
  • docs: added Callback to documentation and examples. by @maccesch in #1926
  • Add replace property to form component by @koopa1338 in #1923
  • feat: add a derive macro for create_slice() by @SadraMoh in #1867
  • chore: cargo doc -- removed lint warnings. by @martinfrances107 in #1936
  • docs: Improve create_resource docs by @nikhilraojl in #1918
  • chore: remove wee_alloc to make Dependabot happy by @gbj in #1938
  • fix: misaligned </head> tags in streaming responses (closes #1930) by @gbj in #1932
  • fix: use separate key in hydration ID for router outlets (closes #1909) by @gbj in #1939
  • chore: fix SSR tests by @gbj in #1943

New Contributors

Full Changelog: v0.5.1...v0.5.2

Don't miss a new leptos release

NewReleases is sending notifications on new releases.