fix replacing fragments

This commit is contained in:
Evan Almloff 2024-01-19 19:23:01 -06:00
parent 85c7c22619
commit b53ba7b5c7
3 changed files with 10 additions and 7 deletions

View file

@ -284,8 +284,8 @@ impl VirtualDom {
// create the new children afresh.
if shared_keys.is_empty() {
if !old.is_empty() {
self.remove_nodes(to, &old[1..], None);
old[0].replace(new, parent, self, to);
let m = self.create_children(to, new, parent);
self.remove_nodes(to, old, Some(m));
} else {
// I think this is wrong - why are we appending?
// only valid of the if there are no trailing elements

View file

@ -297,8 +297,11 @@ impl VNode {
dom.reclaim(id)
}
Fragment(nodes) => {
for node in nodes {
node.remove_node(dom, to, replace_with, gen_muts)
for node in &nodes[..nodes.len() - 1] {
node.remove_node(dom, to, None, gen_muts)
}
if let Some(last_node) = nodes.last() {
last_node.remove_node(dom, to, replace_with, gen_muts)
}
}
};

View file

@ -347,11 +347,11 @@ fn no_common_keys() {
assert_eq!(
dom.render_immediate_to_vec().santize().edits,
[
LoadTemplate { name: "template", index: 0, id: ElementId(4) },
LoadTemplate { name: "template", index: 0, id: ElementId(5) },
LoadTemplate { name: "template", index: 0, id: ElementId(6) },
Remove { id: ElementId(3) },
Remove { id: ElementId(2) },
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
LoadTemplate { name: "template", index: 0, id: ElementId(3) },
LoadTemplate { name: "template", index: 0, id: ElementId(4) },
ReplaceWith { id: ElementId(1), m: 3 }
]
);