diff --git a/src/virtual_dom/vtext.rs b/src/virtual_dom/vtext.rs index c566f7698f2..140704d8c4f 100644 --- a/src/virtual_dom/vtext.rs +++ b/src/virtual_dom/vtext.rs @@ -46,14 +46,11 @@ impl VDiff for VText { sibling } - /// Renders virtual node over existent `TextNode`, but - /// only if value of text had changed. - /// Parameter `previous_sibling` is necessary for `VTag` and `VList` which - /// has children and renders them. + /// Renders virtual node over existing `TextNode`, but only if value of text had changed. fn apply( &mut self, parent: &Element, - _: Option<&Node>, + previous_sibling: Option<&Node>, ancestor: Option>, _: &Scope, ) -> Option { @@ -88,6 +85,12 @@ impl VDiff for VText { parent .insert_before(&element, &ancestor) .expect("can't insert text before ancestor"); + } else if let Some(next_sibling) = + previous_sibling.and_then(|previous_sibling| previous_sibling.next_sibling()) + { + parent + .insert_before(&element, &next_sibling) + .expect("can't insert text before next_sibling"); } else { parent.append_child(&element); }