Skip to content

Commit

Permalink
Fix diff for VText nodes (yewstack#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry authored and llebout committed Jan 20, 2020
1 parent feebec8 commit 185273e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/virtual_dom/vtext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ impl<COMP: Component> VDiff for VText<COMP> {
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<VNode<Self::Component>>,
_: &Scope<Self::Component>,
) -> Option<Node> {
Expand Down Expand Up @@ -88,6 +85,12 @@ impl<COMP: Component> VDiff for VText<COMP> {
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);
}
Expand Down

0 comments on commit 185273e

Please sign in to comment.