v0.6.12

leptos-rs/leptosv0.6.12Jun 2, 2024by gbj

AI Summary

Feature release adding `impl Trait` support in component props and dynamic attribute spreading capabilities.

Key Highlights

  • Support for `impl Trait` syntax directly in component props.
  • Support for spreading dynamic attributes from one component to another.
  • Added ability to use multiple classes in view macro using array syntax.
  • Added `input_derive` parameter to `#[server]` macro.

New Features

  • `impl Trait` in component props
  • Dynamic attribute spreading between components
  • Array syntax for multiple classes
  • input_derive parameter for #[server] macro

Full Release Notes

This is mainly a maintenance release, but includes a couple new features that I want to point out:

## `impl Trait` in Component Props

You can now use `impl Trait` syntax directly in component props, rather than explicitly specifying a generic and a `where` clause

### before
```rust
#[component]
fn ProgressBar<F>(#[prop(default = 100)] max: u16, progress: F) -> impl IntoView
where
    F: Fn() -> i32 + 'static,
{
    view! {
        <progress
            max=max
            value=progress
        />
    }
}
```

### after
```rust
#[component]
fn ProgressBar(
    #[prop(default = 100)] max: u16,
    progress: impl Fn() -> i32 + 'static,
) -> impl IntoView {
    view! {
        <progress
            max=max
            value=progress
        />
    }
}
```

## Support spreading dynamic attributes from one component to another

In the following code `Bar` doesn't currently inherit attributes from `Foo` when it spreads its attributes. PR #2534 fixes this.

```rust
fn main() {
    let (count, set_count) = create_signal(0);

    mount_to_body(move || {
        view! {
            <Foo
                attr:hello=move || count.get().to_string()
            />

            <button on:click=move|_| { set_count.update(|count| *count += 1) }>"+ count"</button>
        }
    });
}

#[component]
fn Foo(#[prop(attrs)] attrs: Vec<(&'static str, Attribute)>) -> impl IntoView {
    view! {
        <Bar {..attrs} />
    }
}

#[component]
fn Bar(#[prop(attrs)] attrs: Vec<(&'static str, Attribute)>) -> impl IntoView {
    view! {
        <div {..attrs}>"hello world"</div>
    }
}
```

## Complete Changelog
* Update spin_sdk to spin v3 by @benwis in https://github.com/leptos-rs/leptos/pull/2525
* Add beginner tip to ErrorBoundary by @sjud in https://github.com/leptos-rs/leptos/pull/2385
* Minor: Bumped serde_qs to 0.13. by @martinfrances107 in https://github.com/leptos-rs/leptos/pull/2512
* fix: do not submit `<ActionForm>` on `formmethod="dialog"` submission (closes #2523) by @gbj in https://github.com/leptos-rs/leptos/pull/2531
* Add id to ActionForm and MultiActionForm by @benwis in https://github.com/leptos-rs/leptos/pull/2535
* Minor: Bumped trunk-action to 0.5. by @martinfrances107 in https://github.com/leptos-rs/leptos/pull/2533
* chore: publish `Oco` separately as `oco_ref` crate so that it can be used elsewhere by @gbj in https://github.com/leptos-rs/leptos/pull/2536
* Adding Russian book branch by @solweo in https://github.com/leptos-rs/leptos/pull/2516
* fix: make TextProp's IntoView and IntoAttribute impls reactive by @0e4ef622 in https://github.com/leptos-rs/leptos/pull/2518
* feat: spread component attrs by @Upbolt in https://github.com/leptos-rs/leptos/pull/2534
* docs: remove unnecessary type parameter and trait bound in component macro 'bad' example by @ethanniser in https://github.com/leptos-rs/leptos/pull/2520
* Adds ability to use multiple classes in view macro using array syntax. by @bicarlsen in https://github.com/leptos-rs/leptos/pull/2532
* Add 'create_query_signal_with_options' to leptos_router by @kryesh in https://github.com/leptos-rs/leptos/pull/2517
* projects directory with 4 projects by @sjud in https://github.com/leptos-rs/leptos/pull/2500
* docs: add caveats for ProtectedRoute by @gbj in https://github.com/leptos-rs/leptos/pull/2558
* Update leptos-spin-macro reference by @itowlson in https://github.com/leptos-rs/leptos/pull/2570
* Minor: examples/server_fns_axum FileWatcher logs errors to the console. by @martinfrances107 in https://github.com/leptos-rs/leptos/pull/2547
* Add an example for generating sitemaps by @JoeyMckenzie in https://github.com/leptos-rs/leptos/pull/2553
* Added an Index to Project README by @sjud in https://github.com/leptos-rs/leptos/pull/2555
* added project by @sjud in https://github.com/leptos-rs/leptos/pull/2556
* docs: clarify the purpose of local resources by @gbj in https://github.com/leptos-rs/leptos/pull/2543
* Use trunk built-in way of handling tailwind by @SleeplessOne1917 in https://github.com/leptos-rs/leptos/pull/2557
* Debug NodeRef Warning (#2414) by @martinfrances107 in https://github.com/leptos-rs/leptos/pull/2467
* feat: add `input_derive` parameter to `#[server]` macro (closes #2544) by @luxalpa in https://github.com/leptos-rs/leptos/pull/2545
* Fix `empty_docs` warnings in `#[component]` macro by @abusch in https://github.com/leptos-rs/leptos/pull/2574
* fix: don't insert empty child for comment/doctype (closes #2549) by @gbj in https://github.com/leptos-rs/leptos/pull/2581
* fix: allow temporaries as props (closes #2541) by @gbj in https://github.com/leptos-rs/leptos/pull/2582
* The counter example, with Dwarf debugging (breakpoints, single stepping in vscode and the browser) by @Hecatron in https://github.com/leptos-rs/leptos/pull/2563
* fix: StoredValue and Resource panic during cleanup by @luxalpa in https://github.com/leptos-rs/leptos/pull/2583
* fix: only issue NodeRef warning in debug mode (necessary to compile in `--release`) by @gbj in https://github.com/leptos-rs/leptos/pull/2587
* fix: grammar typo for MultiActon doc comment by @pitoniak32 in https://github.com/leptos-rs/leptos/pull/2589
* Example using the bevy 3d game engine and leptos by @Hecatron in https://github.com/leptos-rs/leptos/pull/2577
* feat: `#[component]` now handles `impl Trait` by converting to generic type params, fix #2274 by @MingweiSamuel in https://github.com/leptos-rs/leptos/pull/2599
* Allow slice! macro to index tuples by @SleeplessOne1917 in https://github.com/leptos-rs/leptos/pull/2598
* fix: URL encoding issue (closes #2602) by @luxalpa in https://github.com/leptos-rs/leptos/pull/2601

## New Contributors
* @0e4ef622 made their first contribution in https://github.com/leptos-rs/leptos/pull/2518
* @ethanniser made their first contribution in https://github.com/leptos-rs/leptos/pull/2520
* @bicarlsen made their first contribution in https://github.com/leptos-rs/leptos/pull/2532
* @kryesh made their first contribution in https://github.com/leptos-rs/leptos/pull/2517
* @JoeyMckenzie made their first contribution in https://github.com/leptos-rs/leptos/pull/2553
* @abusch made their first contribution in https://github.com/leptos-rs/leptos/pull/2574
* @Hecatron made their first contribution in https://github.com/leptos-rs/leptos/pull/2563
* @pitoniak32 made their first contribution in https://github.com/leptos-rs/leptos/pull/2589
* @MingweiSamuel made their first contribution in https://github.com/leptos-rs/leptos/pull/2599

**Full Changelog**: https://github.com/leptos-rs/leptos/compare/v0.6.11...v0.6.12