diff --git a/packages/yew/src/html/conversion/into_prop_value.rs b/packages/yew/src/html/conversion/into_prop_value.rs index 3b9b3666432..608268eec67 100644 --- a/packages/yew/src/html/conversion/into_prop_value.rs +++ b/packages/yew/src/html/conversion/into_prop_value.rs @@ -198,7 +198,7 @@ impl IntoPropValue for ChildrenRenderer { impl IntoPropValue for VChild { #[inline] fn into_prop_value(self) -> VList { - VList::from_iter([VNode::from(self)]) + VList::from(VNode::from(self)) } } @@ -211,7 +211,7 @@ impl IntoPropValue> for AttrValue { impl IntoPropValue for Vec { #[inline] fn into_prop_value(self) -> VNode { - VNode::VList(Rc::new(VList::from_iter(self))) + VNode::VList(Rc::new(VList::from(self))) } } diff --git a/packages/yew/src/virtual_dom/vlist.rs b/packages/yew/src/virtual_dom/vlist.rs index e861e41d817..70198429df5 100644 --- a/packages/yew/src/virtual_dom/vlist.rs +++ b/packages/yew/src/virtual_dom/vlist.rs @@ -92,6 +92,34 @@ impl From>>> for VList { } } +impl From> for VList { + fn from(children: Vec) -> Self { + if children.is_empty() { + VList::new() + } else { + let mut vlist = VList { + children: Some(Rc::new(children)), + fully_keyed: FullyKeyedState::Unknown, + key: None, + }; + vlist.recheck_fully_keyed(); + vlist + } + } +} + +impl From for VList { + fn from(child: VNode) -> Self { + let mut vlist = VList { + children: Some(Rc::new(vec![child])), + fully_keyed: FullyKeyedState::Unknown, + key: None, + }; + vlist.recheck_fully_keyed(); + vlist + } +} + impl VList { /// Creates a new empty [VList] instance. pub const fn new() -> Self { diff --git a/packages/yew/src/virtual_dom/vnode.rs b/packages/yew/src/virtual_dom/vnode.rs index ff8e5dd9600..8accae27119 100644 --- a/packages/yew/src/virtual_dom/vnode.rs +++ b/packages/yew/src/virtual_dom/vnode.rs @@ -65,7 +65,7 @@ impl VNode { match *self { Self::VList(ref mut m) => return Rc::make_mut(m), _ => { - *self = VNode::VList(Rc::new(VList::from_iter([mem::take(self)]))); + *self = VNode::VList(Rc::new(VList::from(mem::take(self)))); } } }