diff --git a/packages/core/src/arena.rs b/packages/core/src/arena.rs
index 9d723d89c..b89afb4cd 100644
--- a/packages/core/src/arena.rs
+++ b/packages/core/src/arena.rs
@@ -126,11 +126,9 @@ impl VirtualDom {
}
});
- for root in node.root_ids {
- if let Some(id) = root.get() {
- if id.0 != 0 {
- self.try_reclaim(id);
- }
+ for id in &node.root_ids {
+ if id.0 != 0 {
+ self.try_reclaim(id);
}
}
}
diff --git a/packages/core/src/create.rs b/packages/core/src/create.rs
index e4d3e08c3..65dccc482 100644
--- a/packages/core/src/create.rs
+++ b/packages/core/src/create.rs
@@ -25,6 +25,10 @@ impl<'b> VirtualDom {
/// Create this template and write its mutations
pub(crate) fn create(&mut self, node: &'b VNode<'b>) -> usize {
+ // Intialize the root nodes slice
+ node.root_ids
+ .intialize(vec![ElementId(0); node.template.get().roots.len()].into_boxed_slice());
+
// The best renderers will have templates prehydrated and registered
// Just in case, let's create the template using instructions anyways
if !self.templates.contains_key(&node.template.get().name) {
@@ -213,7 +217,7 @@ impl<'b> VirtualDom {
fn load_template_root(&mut self, template: &VNode, root_idx: usize) -> ElementId {
// Get an ID for this root since it's a real root
let this_id = self.next_root(template, root_idx);
- template.root_ids[root_idx].set(Some(this_id));
+ template.root_ids.set(root_idx, this_id);
self.mutations.push(LoadTemplate {
name: template.template.get().name,
diff --git a/packages/core/src/diff.rs b/packages/core/src/diff.rs
index 3082c34a4..6cbad2828 100644
--- a/packages/core/src/diff.rs
+++ b/packages/core/src/diff.rs
@@ -108,11 +108,7 @@ impl<'b> VirtualDom {
});
// Make sure the roots get transferred over while we're here
- left_template
- .root_ids
- .iter()
- .zip(right_template.root_ids.iter())
- .for_each(|(left, right)| right.set(left.get()));
+ right_template.root_ids.transfer(&left_template.root_ids);
}
fn diff_dynamic_node(
@@ -662,7 +658,7 @@ impl<'b> VirtualDom {
Some(node) => node,
None => {
self.mutations.push(Mutation::PushRoot {
- id: node.root_ids[idx].get().unwrap(),
+ id: node.root_ids.get(idx).unwrap(),
});
return 1;
}
@@ -793,7 +789,7 @@ impl<'b> VirtualDom {
if let Some(dy) = node.dynamic_root(idx) {
self.remove_dynamic_node(dy, gen_muts);
} else {
- let id = node.root_ids[idx].get().unwrap();
+ let id = node.root_ids.get(idx).unwrap();
if gen_muts {
self.mutations.push(Mutation::Remove { id });
}
@@ -889,7 +885,7 @@ impl<'b> VirtualDom {
fn find_first_element(&self, node: &'b VNode<'b>) -> ElementId {
match node.dynamic_root(0) {
- None => node.root_ids[0].get().unwrap(),
+ None => node.root_ids.get(0).unwrap(),
Some(Text(t)) => t.id.get().unwrap(),
Some(Fragment(t)) => self.find_first_element(&t[0]),
Some(Placeholder(t)) => t.id.get().unwrap(),
@@ -905,7 +901,7 @@ impl<'b> VirtualDom {
fn find_last_element(&self, node: &'b VNode<'b>) -> ElementId {
match node.dynamic_root(node.template.get().roots.len() - 1) {
- None => node.root_ids.last().unwrap().get().unwrap(),
+ None => node.root_ids.last().unwrap(),
Some(Text(t)) => t.id.get().unwrap(),
Some(Fragment(t)) => self.find_last_element(t.last().unwrap()),
Some(Placeholder(t)) => t.id.get().unwrap(),
diff --git a/packages/core/src/fragment.rs b/packages/core/src/fragment.rs
index 623f9b340..a9e919bfa 100644
--- a/packages/core/src/fragment.rs
+++ b/packages/core/src/fragment.rs
@@ -32,7 +32,7 @@ pub fn Fragment<'a>(cx: Scope<'a, FragmentProps<'a>>) -> Element {
key: children.key,
parent: children.parent,
template: children.template.clone(),
- root_ids: children.root_ids,
+ root_ids: children.root_ids.clone(),
dynamic_nodes: children.dynamic_nodes,
dynamic_attrs: children.dynamic_attrs,
})
diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs
index 5a325d2b9..41b312b3d 100644
--- a/packages/core/src/nodes.rs
+++ b/packages/core/src/nodes.rs
@@ -5,7 +5,7 @@ use bumpalo::boxed::Box as BumpBox;
use bumpalo::Bump;
use std::{
any::{Any, TypeId},
- cell::{Cell, RefCell},
+ cell::{Cell, RefCell, UnsafeCell},
fmt::Arguments,
future::Future,
};
@@ -46,7 +46,7 @@ pub struct VNode<'a> {
/// The IDs for the roots of this template - to be used when moving the template around and removing it from
/// the actual Dom
- pub root_ids: bumpalo::collections::Vec<'a, Cell