Fix component names when they are re-exported (#2744)

* Fix component names when they are re-exported
* Fix read only signal props expansion
This commit is contained in:
Evan Almloff 2024-07-30 21:28:19 +02:00 committed by GitHub
parent 34bdcd15cf
commit 115cc0ad42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 9 additions and 23 deletions

View file

@ -1420,9 +1420,9 @@ Finally, call `.build()` to create the instance of `{name}`.
pub fn into_vcomponent<M: 'static>( pub fn into_vcomponent<M: 'static>(
self, self,
render_fn: impl dioxus_core::prelude::ComponentFunction<#original_name #ty_generics, M>, render_fn: impl dioxus_core::prelude::ComponentFunction<#original_name #ty_generics, M>,
component_name: &'static str,
) -> dioxus_core::VComponent { ) -> dioxus_core::VComponent {
use dioxus_core::prelude::ComponentFunction; use dioxus_core::prelude::ComponentFunction;
let component_name = ::std::any::type_name_of_val(&render_fn);
dioxus_core::VComponent::new(move |wrapper: Self| render_fn.rebuild(wrapper.inner), self, component_name) dioxus_core::VComponent::new(move |wrapper: Self| render_fn.rebuild(wrapper.inner), self, component_name)
} }
} }

View file

@ -57,12 +57,9 @@ pub trait Properties: Clone + Sized + 'static {
fn memoize(&mut self, other: &Self) -> bool; fn memoize(&mut self, other: &Self) -> bool;
/// Create a component from the props. /// Create a component from the props.
fn into_vcomponent<M: 'static>( fn into_vcomponent<M: 'static>(self, render_fn: impl ComponentFunction<Self, M>) -> VComponent {
self, let type_name = std::any::type_name_of_val(&render_fn);
render_fn: impl ComponentFunction<Self, M>, VComponent::new(render_fn, self, type_name)
component_name: &'static str,
) -> VComponent {
VComponent::new(render_fn, self, component_name)
} }
} }
@ -121,10 +118,7 @@ where
#[warnings::warning] #[warnings::warning]
pub(crate) fn component_called_as_function<C: ComponentFunction<P, M>, P, M>(_: C) { pub(crate) fn component_called_as_function<C: ComponentFunction<P, M>, P, M>(_: C) {
// We trim WithOwner from the end of the type name for component with a builder that include a special owner which may not match the function name directly // We trim WithOwner from the end of the type name for component with a builder that include a special owner which may not match the function name directly
let mut type_name = std::any::type_name::<C>(); let type_name = std::any::type_name::<C>();
if let Some((_, after_colons)) = type_name.rsplit_once("::") {
type_name = after_colons;
}
let component_name = Runtime::with(|rt| { let component_name = Runtime::with(|rt| {
current_scope_id() current_scope_id()
.ok() .ok()

View file

@ -29,12 +29,12 @@ pub(crate) fn RootScopeWrapper(props: RootProps<VComponent>) -> Element {
Box::new([]), Box::new([]),
))) )))
.build() .build()
.into_vcomponent(SuspenseBoundary, "SuspenseBoundary") .into_vcomponent(SuspenseBoundary)
})]), })]),
Box::new([]), Box::new([]),
))) )))
.build() .build()
.into_vcomponent(ErrorBoundary, "ErrorBoundary"), .into_vcomponent(ErrorBoundary),
)]), )]),
Box::new([]), Box::new([]),
)) ))

View file

@ -178,8 +178,8 @@ impl SuspenseBoundaryPropsWithOwner {
pub fn into_vcomponent<M: 'static>( pub fn into_vcomponent<M: 'static>(
self, self,
render_fn: impl ComponentFunction<SuspenseBoundaryProps, M>, render_fn: impl ComponentFunction<SuspenseBoundaryProps, M>,
component_name: &'static str,
) -> VComponent { ) -> VComponent {
let component_name = std::any::type_name_of_val(&render_fn);
VComponent::new( VComponent::new(
move |wrapper: Self| render_fn.rebuild(wrapper.inner), move |wrapper: Self| render_fn.rebuild(wrapper.inner),
self, self,

View file

@ -24,7 +24,7 @@ use std::{collections::HashSet, vec};
use syn::{ use syn::{
parse::{Parse, ParseStream}, parse::{Parse, ParseStream},
spanned::Spanned, spanned::Spanned,
token, AngleBracketedGenericArguments, Expr, Ident, PathArguments, Result, token, AngleBracketedGenericArguments, Expr, PathArguments, Result,
}; };
#[derive(PartialEq, Eq, Clone, Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
@ -92,9 +92,6 @@ impl ToTokens for Component {
// Create props either from manual props or from the builder approach // Create props either from manual props or from the builder approach
let props = self.create_props(); let props = self.create_props();
// Make sure we stringify the component name
let fn_name = self.fn_name().to_string();
// Make sure we emit any errors // Make sure we emit any errors
let diagnostics = &self.diagnostics; let diagnostics = &self.diagnostics;
@ -109,7 +106,6 @@ impl ToTokens for Component {
#props #props
}).into_vcomponent( }).into_vcomponent(
#name #generics, #name #generics,
#fn_name
); );
#diagnostics #diagnostics
__comp __comp
@ -302,10 +298,6 @@ impl Component {
.collect() .collect()
} }
fn fn_name(&self) -> Ident {
self.name.segments.last().unwrap().ident.clone()
}
fn empty(name: syn::Path, generics: Option<AngleBracketedGenericArguments>) -> Self { fn empty(name: syn::Path, generics: Option<AngleBracketedGenericArguments>) -> Self {
let mut diagnostics = Diagnostics::new(); let mut diagnostics = Diagnostics::new();
diagnostics.push( diagnostics.push(