瀏覽代碼

fix replacing fragments

Evan Almloff 1 年之前
父節點
當前提交
b53ba7b5c7
共有 3 個文件被更改,包括 10 次插入7 次删除
  1. 2 2
      packages/core/src/diff/iterator.rs
  2. 5 2
      packages/core/src/diff/node.rs
  3. 3 3
      packages/core/tests/diff_keyed_list.rs

+ 2 - 2
packages/core/src/diff/iterator.rs

@@ -284,8 +284,8 @@ impl VirtualDom {
         // create the new children afresh.
         // create the new children afresh.
         if shared_keys.is_empty() {
         if shared_keys.is_empty() {
             if !old.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 {
             } else {
                 // I think this is wrong - why are we appending?
                 // I think this is wrong - why are we appending?
                 // only valid of the if there are no trailing elements
                 // only valid of the if there are no trailing elements

+ 5 - 2
packages/core/src/diff/node.rs

@@ -297,8 +297,11 @@ impl VNode {
                 dom.reclaim(id)
                 dom.reclaim(id)
             }
             }
             Fragment(nodes) => {
             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)
                 }
                 }
             }
             }
         };
         };

+ 3 - 3
packages/core/tests/diff_keyed_list.rs

@@ -347,11 +347,11 @@ fn no_common_keys() {
     assert_eq!(
     assert_eq!(
         dom.render_immediate_to_vec().santize().edits,
         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(3) },
             Remove { id: ElementId(2) },
             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 }
             ReplaceWith { id: ElementId(1), m: 3 }
         ]
         ]
     );
     );