From 9b5a79700874c60aa7868264723bc85754757e90 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 11 Jan 2024 10:34:08 -0600 Subject: [PATCH 1/4] check for duplicate event listeners in the rsx macro --- packages/core/src/virtual_dom.rs | 7 ------- packages/rsx/src/element.rs | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 28ccbc76a..6c2b64276 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -401,13 +401,6 @@ impl VirtualDom { } } }); - - // Break if this is the exact target element. - // This means we won't call two listeners with the same name on the same element. This should be - // documented, or be rejected from the rsx! macro outright - if target_path == this_path { - break; - } } } diff --git a/packages/rsx/src/element.rs b/packages/rsx/src/element.rs index e62fc6d6e..9b6ab063f 100644 --- a/packages/rsx/src/element.rs +++ b/packages/rsx/src/element.rs @@ -95,6 +95,27 @@ impl Parse for Element { let span = content.span(); if name_str.starts_with("on") { + // check for any duplicate event listeners + if attributes.iter().any(|f| { + if let AttributeType::Named(ElementAttrNamed { + attr: + ElementAttr { + name: ElementAttrName::BuiltIn(n), + value: ElementAttrValue::EventTokens(_), + }, + .. + }) = f + { + n == &name_str + } else { + false + } + }) { + return Err(syn::Error::new( + name.span(), + format!("Duplicate event listener `{}`", name), + )); + } attributes.push(attribute::AttributeType::Named(ElementAttrNamed { el_name: el_name.clone(), attr: ElementAttr { From b6ea395338ab6cf7e569ec1ff1504720d221b7ae Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 11 Jan 2024 15:40:44 -0600 Subject: [PATCH 2/4] enable serde dependency in the html crate even if eval is disabled --- packages/html/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/html/Cargo.toml b/packages/html/Cargo.toml index 82d1640e3..78d0a3caa 100644 --- a/packages/html/Cargo.toml +++ b/packages/html/Cargo.toml @@ -52,6 +52,8 @@ serde_json = "1" [features] default = ["serialize", "mounted", "eval"] serialize = [ + "serde", + "serde_json", "serde_repr", "euclid/serde", "keyboard-types/serde", From 4ef6f78657576bdec2cfb22bb977925f11a4ed34 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 11 Jan 2024 16:22:28 -0600 Subject: [PATCH 3/4] fix duplicate listeners in the autoformat tests --- packages/autofmt/tests/samples/attributes.rsx | 12 ------------ packages/autofmt/tests/samples/complex.rsx | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/autofmt/tests/samples/attributes.rsx b/packages/autofmt/tests/samples/attributes.rsx index fa08b1cf4..4a0bdcdda 100644 --- a/packages/autofmt/tests/samples/attributes.rsx +++ b/packages/autofmt/tests/samples/attributes.rsx @@ -12,18 +12,6 @@ rsx! { let blah = 120; true }, - onclick: move |_| { - let blah = 120; - true - }, - onclick: move |_| { - let blah = 120; - true - }, - onclick: move |_| { - let blah = 120; - true - }, div { div { "hi" } h2 { class: "asd" } diff --git a/packages/autofmt/tests/samples/complex.rsx b/packages/autofmt/tests/samples/complex.rsx index 1bf29a767..88248c027 100644 --- a/packages/autofmt/tests/samples/complex.rsx +++ b/packages/autofmt/tests/samples/complex.rsx @@ -6,7 +6,7 @@ rsx! { show_user_menu.set(!show_user_menu.get()); evt.cancel_bubble(); }, - onclick: move |evt| show_user_menu.set(!show_user_menu.get()), + onmousedown: move |evt| show_user_menu.set(!show_user_menu.get()), span { class: "inline-block mr-4", icons::icon_14 {} } span { "Settings" } } From a7a6645963b319e94f9655f031138135c5e6761d Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Thu, 11 Jan 2024 14:55:56 -0800 Subject: [PATCH 4/4] dont use magnanis for todomv --- examples/todomvc.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/todomvc.rs b/examples/todomvc.rs index f3cb59f09..d5e56dd1a 100644 --- a/examples/todomvc.rs +++ b/examples/todomvc.rs @@ -7,8 +7,6 @@ fn main() { dioxus_desktop::launch(app); } -const _STYLE: &str = manganis::mg!(file("./examples/assets/todomvc.css")); - #[derive(PartialEq, Eq, Clone, Copy)] pub enum FilterState { All, @@ -49,6 +47,7 @@ pub fn app(cx: Scope<()>) -> Element { cx.render(rsx! { section { class: "todoapp", + style { {include_str!("./assets/todomvc.css")} } TodoHeader { todos: todos } section { class: "main", if !todos.is_empty() {