Evan Almloff 2 gadi atpakaļ
vecāks
revīzija
21ca1599eb
2 mainītis faili ar 16 papildinājumiem un 5 dzēšanām
  1. 3 1
      packages/core/src/create.rs
  2. 13 4
      packages/core/src/diff.rs

+ 3 - 1
packages/core/src/create.rs

@@ -255,7 +255,9 @@ impl<'b> VirtualDom {
         root: ElementId,
         root: ElementId,
         node: &VNode,
         node: &VNode,
     ) {
     ) {
-        while let Some((mut attr_id, path)) = attrs.next_if(|(_, p)| p[0] == root_idx) {
+        while let Some((mut attr_id, path)) =
+            attrs.next_if(|(_, p)| p.first().copied() == Some(root_idx))
+        {
             let id = self.assign_static_node_as_dynamic(path, root, node, attr_id);
             let id = self.assign_static_node_as_dynamic(path, root, node, attr_id);
 
 
             loop {
             loop {

+ 13 - 4
packages/core/src/diff.rs

@@ -58,10 +58,11 @@ impl<'b> VirtualDom {
         // If hot reloading is enabled, we need to make sure we're using the latest template
         // If hot reloading is enabled, we need to make sure we're using the latest template
         #[cfg(debug_assertions)]
         #[cfg(debug_assertions)]
         if let Some(template) = self.templates.get(right_template.template.get().name) {
         if let Some(template) = self.templates.get(right_template.template.get().name) {
-            let prev_template = right_template.template.get();
-            if *template != prev_template {
+            if *template != right_template.template.get() {
                 right_template.template.set(*template);
                 right_template.template.set(*template);
-                return self.replace(left_template, [right_template]);
+                if *template != left_template.template.get() {
+                    return self.replace(left_template, [right_template]);
+                }
             }
             }
         }
         }
 
 
@@ -803,7 +804,15 @@ impl<'b> VirtualDom {
         let mut id = None;
         let mut id = None;
         for (idx, attr) in node.dynamic_attrs.iter().enumerate() {
         for (idx, attr) in node.dynamic_attrs.iter().enumerate() {
             // We'll clean up the root nodes either way, so don't worry
             // We'll clean up the root nodes either way, so don't worry
-            if node.template.get().attr_paths[idx].len() == 1 {
+            let path_len = node
+                .template
+                .get()
+                .attr_paths
+                .get(idx)
+                .map(|path| path.len());
+            // if the path is 1 the attribute is in the root, so we don't need to clean it up
+            // if the path is 0, the attribute is a not attached at all, so we don't need to clean it up
+            if let Some(..=1) = path_len {
                 continue;
                 continue;
             }
             }