|
@@ -81,9 +81,7 @@ impl<'b> VirtualDom {
|
|
|
|
|
|
// The best renderers will have templates prehydrated and registered
|
|
// The best renderers will have templates prehydrated and registered
|
|
// Just in case, let's create the template using instructions anyways
|
|
// Just in case, let's create the template using instructions anyways
|
|
- if !self.templates.contains_key(&node.template.get().name) {
|
|
|
|
- self.register_template(node.template.get());
|
|
|
|
- }
|
|
|
|
|
|
+ self.register_template(node.template.get());
|
|
|
|
|
|
// we know that this will generate at least one mutation per node
|
|
// we know that this will generate at least one mutation per node
|
|
self.mutations
|
|
self.mutations
|
|
@@ -389,30 +387,36 @@ impl<'b> VirtualDom {
|
|
|
|
|
|
/// Insert a new template into the VirtualDom's template registry
|
|
/// Insert a new template into the VirtualDom's template registry
|
|
pub(crate) fn register_template(&mut self, mut template: Template<'static>) {
|
|
pub(crate) fn register_template(&mut self, mut template: Template<'static>) {
|
|
- // First, make sure we mark the template as seen, regardless if we process it
|
|
|
|
let (path, byte_index) = template.name.rsplit_once(':').unwrap();
|
|
let (path, byte_index) = template.name.rsplit_once(':').unwrap();
|
|
let byte_index = byte_index.parse::<usize>().unwrap();
|
|
let byte_index = byte_index.parse::<usize>().unwrap();
|
|
-
|
|
|
|
- // if hot reloading is enabled, then we need to check for a template that has overriten this one
|
|
|
|
- #[cfg(debug_assertions)]
|
|
|
|
- if let Some(mut new_template) = self
|
|
|
|
|
|
+ // First, check if we've already seen this template
|
|
|
|
+ if self
|
|
.templates
|
|
.templates
|
|
- .get_mut(path)
|
|
|
|
- .and_then(|map| map.remove(&usize::MAX))
|
|
|
|
|
|
+ .get(&path)
|
|
|
|
+ .filter(|set| set.contains_key(&byte_index))
|
|
|
|
+ .is_none()
|
|
{
|
|
{
|
|
- // the byte index of the hot reloaded template could be different
|
|
|
|
- new_template.name = template.name;
|
|
|
|
- template = new_template;
|
|
|
|
- }
|
|
|
|
|
|
+ // if hot reloading is enabled, then we need to check for a template that has overriten this one
|
|
|
|
+ #[cfg(debug_assertions)]
|
|
|
|
+ if let Some(mut new_template) = self
|
|
|
|
+ .templates
|
|
|
|
+ .get_mut(path)
|
|
|
|
+ .and_then(|map| map.remove(&usize::MAX))
|
|
|
|
+ {
|
|
|
|
+ // the byte index of the hot reloaded template could be different
|
|
|
|
+ new_template.name = template.name;
|
|
|
|
+ template = new_template;
|
|
|
|
+ }
|
|
|
|
|
|
- self.templates
|
|
|
|
- .entry(path)
|
|
|
|
- .or_default()
|
|
|
|
- .insert(byte_index, template);
|
|
|
|
|
|
+ self.templates
|
|
|
|
+ .entry(path)
|
|
|
|
+ .or_default()
|
|
|
|
+ .insert(byte_index, template);
|
|
|
|
|
|
- // If it's all dynamic nodes, then we don't need to register it
|
|
|
|
- if !template.is_completely_dynamic() {
|
|
|
|
- self.mutations.templates.push(template);
|
|
|
|
|
|
+ // If it's all dynamic nodes, then we don't need to register it
|
|
|
|
+ if !template.is_completely_dynamic() {
|
|
|
|
+ self.mutations.templates.push(template);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|