Fix too restrictive Clone bounds in props with generics (#5451)

* Manually implement Clone for *WithOwner for less restrictive bounds.

* add tests

* fix clippy

---------

Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
Gabriël KonatandEvan Almloff authored and GitHub committed 2026-04-06 13:18:10 -05:00
1 parent d027e26046
commit a07b406699
2 files changed
+45 -2

No files matched your search

+9 -1
View File
@@ -1481,7 +1481,6 @@ Finally, call `.build()` to create the instance of `{name}`.
quote! {
#[doc(hidden)]
#[allow(dead_code, non_camel_case_types, missing_docs)]
#[derive(Clone)]
#vis struct #name #generics_with_bounds #where_clause {
inner: #original_name #ty_generics,
owner: dioxus_core::internal::generational_box::Owner,
@@ -1493,6 +1492,15 @@ Finally, call `.build()` to create the instance of `{name}`.
}
}
impl #original_impl_generics Clone for #name #ty_generics #where_clause {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
owner: self.owner.clone(),
}
}
}
impl #original_impl_generics #name #ty_generics #where_clause {
/// Create a component from the props.
pub fn into_vcomponent<M: 'static>(
+36 -1
View File
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{fmt::Display, marker::PhantomData};
use dioxus::prelude::*;
@@ -104,4 +104,39 @@ fn generic_props_compile() {
p { "{value}" }
}
}
#[derive(Props)]
struct PropsWithOwnerOnlyRequiresStatic<T: 'static> {
value: PhantomData<T>,
trigger_owner: EventHandler<()>,
}
impl<T> PartialEq for PropsWithOwnerOnlyRequiresStatic<T> {
fn eq(&self, _: &Self) -> bool {
true
}
}
impl<T> Clone for PropsWithOwnerOnlyRequiresStatic<T> {
fn clone(&self) -> Self {
PropsWithOwnerOnlyRequiresStatic {
value: PhantomData,
trigger_owner: self.trigger_owner,
}
}
}
fn ReadSignalNoCloneWithOwner<T>(props: PropsWithOwnerOnlyRequiresStatic<T>) -> Element {
rsx! {}
}
#[component]
fn ReadSignalNoClone<T>(value: ReadSignal<T>) -> Element
where
T: PartialEq + Display + 'static,
{
rsx! {
p { "{value}" }
}
}
}