From 8d59c626eac83f21e3b4c548f94f62d7e54789f7 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Sat, 14 Jan 2023 00:19:37 -0800 Subject: [PATCH] fix: listeners should not use hard indexing --- packages/core/src/virtual_dom.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index d8272a57c..b66f53b70 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -349,7 +349,7 @@ impl VirtualDom { /// If you have multiple events, you can call this method multiple times before calling "render_with_deadline" pub fn handle_event( &mut self, - name: &str, + mut name: &str, data: Rc, element: ElementId, bubbles: bool, @@ -384,6 +384,11 @@ impl VirtualDom { data, }; + // Remove the "on" prefix if it exists, TODO, we should remove this and settle on one + if name.starts_with("on") { + name = &name[2..]; + } + // Loop through each dynamic attribute in this template before moving up to the template's parent. while let Some(el_ref) = parent_path { // safety: we maintain references of all vnodes in the element slab @@ -394,9 +399,7 @@ impl VirtualDom { for (idx, attr) in template.dynamic_attrs.iter().enumerate() { let this_path = node_template.attr_paths[idx]; - // listeners are required to be prefixed with "on", but they come back to the virtualdom with that missing - // we should fix this so that we look for "onclick" instead of "click" - if &attr.name[2..] == name && target_path.is_ascendant(&this_path) { + if attr.name == name && target_path.is_ascendant(&this_path) { listeners.push(&attr.value); // Break if the event doesn't bubble anyways