diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index a501644941b..04c47e6cf68 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -330,7 +330,6 @@ impl ToTokens for HtmlElement { let node = match &*name { "input" => { quote! { - ::std::convert::Into::<::yew::virtual_dom::VNode>::into( ::yew::virtual_dom::VTag::__new_input( #value, #checked, @@ -338,26 +337,22 @@ impl ToTokens for HtmlElement { #key, #attributes, #listeners, - ), ) } } "textarea" => { quote! { - ::std::convert::Into::<::yew::virtual_dom::VNode>::into( ::yew::virtual_dom::VTag::__new_textarea( #value, #node_ref, #key, #attributes, #listeners, - ), ) } } _ => { quote! { - ::std::convert::Into::<::yew::virtual_dom::VNode>::into( ::yew::virtual_dom::VTag::__new_other( ::yew::virtual_dom::AttrValue::Static(#name), #node_ref, @@ -365,7 +360,6 @@ impl ToTokens for HtmlElement { #attributes, #listeners, #children, - ), ) } } diff --git a/packages/yew-macro/src/html_tree/html_list.rs b/packages/yew-macro/src/html_tree/html_list.rs index 301b533a92c..961acc27a53 100644 --- a/packages/yew-macro/src/html_tree/html_list.rs +++ b/packages/yew-macro/src/html_tree/html_list.rs @@ -78,9 +78,7 @@ impl ToTokens for HtmlList { }; tokens.extend(quote_spanned! {spanned.span()=> - ::yew::virtual_dom::VNode::VList(::std::rc::Rc::new( - ::yew::virtual_dom::VList::with_children(#children, #key) - )) + ::yew::virtual_dom::VList::with_children(#children, #key) }); } } diff --git a/packages/yew-macro/src/html_tree/mod.rs b/packages/yew-macro/src/html_tree/mod.rs index 266ea31bfd8..67c74349118 100644 --- a/packages/yew-macro/src/html_tree/mod.rs +++ b/packages/yew-macro/src/html_tree/mod.rs @@ -122,8 +122,9 @@ impl ToTokens for HtmlTree { fn to_tokens(&self, tokens: &mut TokenStream) { lint::lint_all(self); match self { + // this is consistent with VNode::default() HtmlTree::Empty => tokens.extend(quote! { - <::yew::virtual_dom::VNode as ::std::default::Default>::default() + ::yew::virtual_dom::VList::new() }), HtmlTree::Component(comp) => comp.to_tokens(tokens), HtmlTree::Element(tag) => tag.to_tokens(tokens), @@ -375,9 +376,7 @@ impl ToTokens for HtmlRootBraced { tokens.extend(quote_spanned! {brace.span.span()=> { - ::yew::virtual_dom::VNode::VList(::std::rc::Rc::new( - ::yew::virtual_dom::VList::with_children(#children, ::std::option::Option::None) - )) + ::yew::virtual_dom::VList::with_children(#children, ::std::option::Option::None) } }); } diff --git a/packages/yew-macro/tests/html_macro/component-fail.stderr b/packages/yew-macro/tests/html_macro/component-fail.stderr index 440ffed4c64..f45a04ca25e 100644 --- a/packages/yew-macro/tests/html_macro/component-fail.stderr +++ b/packages/yew-macro/tests/html_macro/component-fail.stderr @@ -710,21 +710,23 @@ note: required by a bound in `ChildContainerPropertiesBuilder::children` | -------- required by a bound in this = note: this error originates in the macro `html` which comes from the expansion of the derive macro `Properties` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `VChild: From` is not satisfied +error[E0277]: the trait bound `VChild: From` is not satisfied --> tests/html_macro/component-fail.rs:118:29 | 118 | html! { <> }; - | ^ the trait `From` is not implemented for `VChild` + | ^ the trait `From` is not implemented for `VChild` | - = note: required because of the requirements on the impl of `Into>` for `VNode` + = note: required because of the requirements on the impl of `Into>` for `yew::virtual_dom::VList` -error[E0277]: the trait bound `VNode: IntoPropValue>>` is not satisfied +error[E0277]: the trait bound `yew::virtual_dom::VTag: IntoPropValue>>` is not satisfied --> tests/html_macro/component-fail.rs:119:14 | 119 | html! { }; - | ^^^^^^^^^^^^^^ the trait `IntoPropValue>>` is not implemented for `VNode` + | ^^^^^^^^^^^^^^ the trait `IntoPropValue>>` is not implemented for `yew::virtual_dom::VTag` | - = help: the trait `IntoPropValue>` is implemented for `VNode` + = help: the following other types implement trait `IntoPropValue`: + >> + > note: required by a bound in `ChildContainerPropertiesBuilder::children` --> tests/html_macro/component-fail.rs:24:17 | diff --git a/packages/yew/src/html/conversion/into_prop_value.rs b/packages/yew/src/html/conversion/into_prop_value.rs index 9b2972b5b93..f118c13409e 100644 --- a/packages/yew/src/html/conversion/into_prop_value.rs +++ b/packages/yew/src/html/conversion/into_prop_value.rs @@ -7,7 +7,7 @@ pub use implicit_clone::ImplicitClone; use crate::callback::Callback; use crate::html::{BaseComponent, ChildrenRenderer, Component, NodeRef, Scope}; -use crate::virtual_dom::{AttrValue, VChild, VList, VNode, VText}; +use crate::virtual_dom::{AttrValue, VChild, VList, VNode, VTag, VText}; impl ImplicitClone for NodeRef {} impl ImplicitClone for Scope {} @@ -153,6 +153,13 @@ impl IntoPropValue for VText { } } +impl IntoPropValue for VTag { + #[inline] + fn into_prop_value(self) -> VNode { + VNode::VTag(Rc::new(self)) + } +} + impl IntoPropValue for () { #[inline] fn into_prop_value(self) -> VNode { @@ -181,6 +188,13 @@ impl IntoPropValue> for VText { } } +impl IntoPropValue> for VTag { + #[inline] + fn into_prop_value(self) -> ChildrenRenderer { + ChildrenRenderer::new(vec![self.into()]) + } +} + impl IntoPropValue for ChildrenRenderer { #[inline] fn into_prop_value(self) -> VList { diff --git a/packages/yew/src/virtual_dom/vnode.rs b/packages/yew/src/virtual_dom/vnode.rs index 8ed18f29c9f..7aca0acfcec 100644 --- a/packages/yew/src/virtual_dom/vnode.rs +++ b/packages/yew/src/virtual_dom/vnode.rs @@ -261,3 +261,37 @@ mod feat_ssr { } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::{function_component, html_nested, Html}; + + #[function_component] + fn Comp() -> Html { + todo!() + } + + #[test] + fn html_nested_types() { + let _vlist: VList = html_nested! { + <> +
{"Hello"}
+
{"World"}
+ + }; + let _vlist2: VList = html_nested! {}; + let _vtext: VText = html_nested!(""); + let _vcomp: VChild = html_nested! { }; + let _vtag: VTag = html_nested! {
}; + let _vtag: VTag = html_nested! {