Skip to content

Complex Into<Callback> props broken with Leptos update #4577

@MikeOnTea

Description

@MikeOnTea

The upgrade from Leptos 0.8.12 to 0.8.14 broke more complex into props in components involving server functions. The error is:

multiple `impl`s satisfying `{closure@test_app.rs}: leptos::prelude::IntoReactiveValue<leptos::prelude::Callback<((),)>, _>` found in the `reactive_graph` crate:
            - impl<I, O, F> leptos::prelude::IntoReactiveValue<leptos::prelude::Callback<I, O>, leptos::prelude::__IntoReactiveValueMarkerCallbackSingleParam> for F
              where <F as std::ops::FnOnce<(I,)>>::Output == O, F: Fn(I), F: std::marker::Send, F: std::marker::Sync, F: 'static;
            - impl<T, I> leptos::prelude::IntoReactiveValue<T, leptos::reactive_graph::__IntoReactiveValueMarkerBaseCase> for I
              where I: std::convert::Into<T>;
note: required by a bound in `TestPropsBuilder::<T, (___pd, ())>::cb`

The most minimal example i managed to come up with is this:

#[component]
fn TestApp() -> impl IntoView {
	let (count, set_count) = signal(0);
	//works with explicit callback:
	//let cb = Callback::new(move |_| *set_count.write() += 1);
	let cb = move |_| *set_count.write() += 1;
	view! {
		<Test<TestFn> cb=cb/>
	}
}

#[server(TestFn)]
async fn test_fn() -> Result<(), ServerFnError> {
	Ok(())
}

#[component]
fn Test<T>(#[prop(optional)] _pd: PhantomData<T>, #[prop(into)] cb: Callback<(<T as ServerFn>::Output,)>) -> impl IntoView
where
	T: Sync + ServerFn<Protocol = Http<PostUrl, Json>> + 'static + Clone + for<'de> serde::Deserialize<'de>,
	<T as ServerFn>::Output: Sync + Clone,
	<T as ServerFn>::Error: Send + Sync + Clone + Display,
	<T as ServerFn>::Client: Client<<T as ServerFn>::Error>,
{
    //the real app of course invokes the callback, but i don't think this is relevant for the example
}

I was only able to reproduce this with such complex callbacks involving server functions, very simple Into Callbacks worked fine. Also, i don't think this is a big deal, in the few places this occurred in my app i just used an explicit Callback as a workaround, so it's probably not worth to invest too much time into this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions