From 3faef30075f9ca93dbea42e2a3db5c3146ede184 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Sat, 17 Dec 2022 01:55:18 -0800 Subject: [PATCH] fix: dont clone callbacks --- packages/core/src/create.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/core/src/create.rs b/packages/core/src/create.rs index 9fe33a52e..0b8eff3d2 100644 --- a/packages/core/src/create.rs +++ b/packages/core/src/create.rs @@ -210,14 +210,27 @@ impl<'b> VirtualDom { // } // Safety: we promise not to re-alias this text later on after committing it to the mutation - let unbounded_value = unsafe { std::mem::transmute(attribute.value.clone()) }; - self.mutations.push(SetAttribute { - name: unbounded_name, - value: unbounded_value, - ns: attribute.namespace, - id, - }); + match &attribute.value { + AttributeValue::Listener(_) => { + self.mutations.push(NewEventListener { + // all listeners start with "on" + name: &unbounded_name[2..], + id, + }) + } + _ => { + // Safety: we promise not to re-alias this text later on after committing it to the mutation + let unbounded_value = unsafe { std::mem::transmute(attribute.value.clone()) }; + + self.mutations.push(SetAttribute { + name: unbounded_name, + value: unbounded_value, + ns: attribute.namespace, + id, + }) + } + } } fn load_template_root(&mut self, template: &VNode, root_idx: usize) -> ElementId {