From 0f01f3fd841639ff4dfe06a6dde9345bacecd5f6 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 15 Jan 2024 10:05:04 -0600 Subject: [PATCH] fix replacing VNodes --- packages/core/src/diff/node.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/core/src/diff/node.rs b/packages/core/src/diff/node.rs index ce9c02f44..ed1e3182b 100644 --- a/packages/core/src/diff/node.rs +++ b/packages/core/src/diff/node.rs @@ -39,6 +39,11 @@ impl VNode { } } + // If the templates are different by name, we need to replace the entire template + if self.templates_are_different(new) { + return self.light_diff_templates(new, dom, to); + } + // Copy over the mount information let mount_id = self.mount.get(); new.mount.set(mount_id); @@ -53,11 +58,6 @@ impl VNode { return; } - // If the templates are different by name, we need to replace the entire template - if self.templates_are_different(new) { - return self.light_diff_templates(new, dom, to); - } - // If the templates are the same, we can diff the attributes and children // Start with the attributes self.diff_attributes(new, dom, to); @@ -553,8 +553,8 @@ impl VNode { .map(|(i, path)| ((i, i), path)) .peekable(), ); - // If this is a debug build, we need to check that the paths are in the correct order because hot reloading can cause scrambled states + // If this is a debug build, we need to check that the paths are in the correct order because hot reloading can cause scrambled states #[cfg(debug_assertions)] let (attrs_sorted, nodes_sorted) = { (sort_bfs(template.attr_paths), sort_bfs(template.node_paths)) }; @@ -754,6 +754,7 @@ impl VNode { loop { for attr in &*self.dynamic_attrs[attr_id] { self.write_attribute(path, attr, id, mount, dom, to); + dom.mounts[mount.0].mounted_attributes[attr_id] = id; } // Only push the dynamic attributes forward if they match the current path (same element)