diff --git a/crates/core/src/dom/component/stateful_component.rs b/crates/core/src/dom/component/stateful_component.rs index 843c2fde1..e6ce2cc0f 100644 --- a/crates/core/src/dom/component/stateful_component.rs +++ b/crates/core/src/dom/component/stateful_component.rs @@ -31,11 +31,12 @@ pub fn register_template( where MSG: 'static, { - let (dom_template, vdom_template) = template::build_template(&view); + let (dom_template, vdom_template) = template::build_template(view); let template = TEMPLATE_LOOKUP.with_borrow_mut(|map| { if let Some(existing) = map.get(&type_id) { existing.clone_node_with_deep(true).expect("deep clone") } else { + log::info!("---->> Adding to template..."); map.insert(type_id, dom_template.clone()); dom_template } @@ -43,6 +44,7 @@ where (template, vdom_template) } + /// lookup for the template pub fn lookup_template(type_id: TypeId) -> Option { TEMPLATE_LOOKUP.with_borrow_mut(|map| { diff --git a/crates/core/src/dom/dom_node.rs b/crates/core/src/dom/dom_node.rs index bbe19548f..88b5eb3a2 100644 --- a/crates/core/src/dom/dom_node.rs +++ b/crates/core/src/dom/dom_node.rs @@ -223,6 +223,8 @@ where #[cfg(feature = "use-template")] { let template = lookup_template(comp.type_id).expect("must have a template"); + //Note: we don't want the patches to be stored in the StatelessModel + //since it has a lifetime, which will infect the Node, Element, Attribute, etc let patches = diff(&comp.vdom_template, &comp.view); log::info!("patching template: {:#?}", patches); let dom_patches = self diff --git a/examples/js-performance-benchmark-sauron/Cargo.toml b/examples/js-performance-benchmark-sauron/Cargo.toml index a99ba4942..bdad507d4 100644 --- a/examples/js-performance-benchmark-sauron/Cargo.toml +++ b/examples/js-performance-benchmark-sauron/Cargo.toml @@ -10,8 +10,8 @@ crate-type = ["cdylib"] [dependencies] rand = { version = "0.8.5", features = ["small_rng"] } getrandom = { version = "0.2.7", features = ["js"] } -#sauron = { path = "../../../sauron", features = ["with-debug", "with-measure", "use-template"] } -sauron = { path = "../../../sauron", features = ["with-debug", "with-measure"] } +sauron = { path = "../../../sauron", features = ["with-debug", "with-measure", "use-template"] } +#sauron = { path = "../../../sauron", features = ["with-debug", "with-measure"] } log = "0.4" console_log = "0.2" console_error_panic_hook = "0.1"