Merge pull request #331 from Demonthos/diff-fix

fix: diff_lazynodes bug adding children
This commit is contained in:
Jon Kelley 2022-04-04 12:15:31 -04:00 committed by GitHub
commit 09d193d999
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View file

@ -423,6 +423,7 @@ impl<'b> DiffState<'b> {
match (old.children.len(), new.children.len()) {
(0, 0) => {}
(0, _) => {
self.mutations.push_root(root);
let created = self.create_children(new.children);
self.mutations.append_children(created as u32);
}

View file

@ -730,3 +730,28 @@ fn remove_list_nokeyed() {
]
);
}
#[test]
fn add_nested_elements() {
let vdom = new_dom();
let (_create, change) = vdom.diff_lazynodes(
rsx! {
div{}
},
rsx! {
div{
div{}
}
},
);
assert_eq!(
change.edits,
[
PushRoot { root: 1 },
CreateElement { root: 2, tag: "div" },
AppendChildren { many: 1 },
]
);
}