-
-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Click events are registered twice when two leptos custom elements are on a page #2564
Comments
If you opt out of event delegation by using |
Yeah, that seems to fix it, thanks! Is there some way to do this simpler? I am not the biggest fan of having to put that flag on all event handlers |
I tried merging the two components into one crate, so the "run" function defines both custom components, and that seemed to fix the issue as well |
So for the sake of clarity/closing this one out: There are several issues here interacting to cause this problem.
0.7 (which is the main branch now) makes delegation opt-in — event delegation has generated enough minor confusion in edge cases over time that it's worth making it an opt-in feature rather than the default IMO. In general, I would also suggest that merging the components into one crate/one WASM binary is always preferable, if it is at all possible; otherwise you end up shipping much more code to the client. i.e., say the binary size of Leptos the framework is K, and the cost of your two components are A and B. If you compile the two crates separately, you are shipping A + B + 2K to the client, as opposed to A + B + K. |
Thanks for the write-up! Just a quick follow up, then. Is it a bad idea to split your leptos app in multiple libs, say one for ui, one for the main app, and so on? I.e. are we adding multiple leptos "instances" on top of each other? Or is that just the case for wasm? |
Describe the bug
You can find a repro case here.
I have defined two web components using your custom-elements crate with leptos as the component framework. The components are very simple to show the bug and are just a button with a click handler. However when embedding both on a site, whenever clicking one of the buttons, two click events are registered (See the video in the repro repo).
If I tried to add the buttons in raw "js", that is, through web-sys with add_event_listener; then only one click event is registered which leads me to think this is a Leptos problem.
You can see a video of the issue here:
Screen.Recording.2024-04-28.at.23.55.58.mov
I hope it makes sense, please tell me if this belongs in the custom-elements repo instead.
Leptos Dependencies
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I would expect only one click event being sent when clicking the button
The text was updated successfully, but these errors were encountered: