From dd109f20d2989872fe69792455a97cef7e93a8b0 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 8 Mar 2024 14:49:56 -0800 Subject: [PATCH] fix #1979: generated Owned impl for the props builder was using the wrong generics. (#2027) This commit fixes the owned impl to use the original generics rather than the build generics. --- packages/core-macro/src/props/mod.rs | 9 +++--- .../signals/examples/read_only_degrade.rs | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 packages/signals/examples/read_only_degrade.rs diff --git a/packages/core-macro/src/props/mod.rs b/packages/core-macro/src/props/mod.rs index 7808239d7..598cb5326 100644 --- a/packages/core-macro/src/props/mod.rs +++ b/packages/core-macro/src/props/mod.rs @@ -1276,7 +1276,8 @@ Finally, call `.build()` to create the instance of `{name}`. }); let (impl_generics, _, _) = generics.split_for_impl(); - let (_, ty_generics, where_clause) = self.generics.split_for_impl(); + let (original_impl_generics, ty_generics, where_clause) = + self.generics.split_for_impl(); let modified_ty_generics = modify_types_generics_hack(&ty_generics, |args| { args.insert( @@ -1344,13 +1345,13 @@ Finally, call `.build()` to create the instance of `{name}`. owner: Owner, } - impl #impl_generics PartialEq for #name #ty_generics #where_clause { + impl #original_impl_generics PartialEq for #name #ty_generics #where_clause { fn eq(&self, other: &Self) -> bool { self.inner.eq(&other.inner) } } - impl #impl_generics #name #ty_generics #where_clause { + impl #original_impl_generics #name #ty_generics #where_clause { /// Create a component from the props. fn into_vcomponent( self, @@ -1362,7 +1363,7 @@ Finally, call `.build()` to create the instance of `{name}`. } } - impl #impl_generics dioxus_core::prelude::Properties for #name #ty_generics #where_clause { + impl #original_impl_generics dioxus_core::prelude::Properties for #name #ty_generics #where_clause { type Builder = (); fn builder() -> Self::Builder { unreachable!() diff --git a/packages/signals/examples/read_only_degrade.rs b/packages/signals/examples/read_only_degrade.rs new file mode 100644 index 000000000..a69101bec --- /dev/null +++ b/packages/signals/examples/read_only_degrade.rs @@ -0,0 +1,30 @@ +//! Signals can degrade into a ReadOnlySignal variant automatically +//! This is done thanks to a conversion by the #[component] macro + +use dioxus::prelude::*; + +fn main() { + launch(app); +} + +fn app() -> Element { + let mut count = use_signal(|| 0); + + rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + Child { + count, + "hiiii" + } + } +} + +#[component] +fn Child(count: ReadOnlySignal, children: Element) -> Element { + rsx! { + div { "Count: {count}" } + {children} + } +}