From 21ca1599eb89f9ed624121b1caf42d0b0d6d48a4 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 22 Dec 2022 15:09:58 -0600 Subject: [PATCH] more bugfixes --- packages/core/src/create.rs | 4 +++- packages/core/src/diff.rs | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/core/src/create.rs b/packages/core/src/create.rs index b526cd161..f2d315034 100644 --- a/packages/core/src/create.rs +++ b/packages/core/src/create.rs @@ -255,7 +255,9 @@ impl<'b> VirtualDom { root: ElementId, 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); loop { diff --git a/packages/core/src/diff.rs b/packages/core/src/diff.rs index 58bb44ac6..ed6e1355b 100644 --- a/packages/core/src/diff.rs +++ b/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 #[cfg(debug_assertions)] 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); - 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; for (idx, attr) in node.dynamic_attrs.iter().enumerate() { // 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; }