Skip to content
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

Open
SorenHolstHansen opened this issue Apr 28, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@SorenHolstHansen
Copy link

SorenHolstHansen commented Apr 28, 2024

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

leptos = { version = "0.6.11", features = ["csr"] }

To Reproduce
Steps to reproduce the behavior:

  1. See https://github.com/SorenHolstHansen/leptos-custom-elements-double-click

Expected behavior
I would expect only one click event being sent when clicking the button

@gbj
Copy link
Collaborator

gbj commented Apr 29, 2024

If you opt out of event delegation by using on:click:undelegated does it work as expected? (I have not tried)

@gbj gbj added the bug Something isn't working label Apr 29, 2024
@SorenHolstHansen
Copy link
Author

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

@SorenHolstHansen
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants