Javascript data-confirm fires multiple times
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- frontend
Research direction
Start in priv/static/phoenix_html.js and inspect the anonymous event-listener registrations used by data-confirm. Compare the approach with Rails' actionview JavaScript implementation. Done means loading phoenix_html.js repeatedly no longer makes the confirmation dialog fire multiple times for one action.
Written by the indexing model from the issue text.
Description
If you're using something like turbolinks, phoenix_html may get loaded multiple times. This leads to a situation where users will have to click the confirm dialog over and over to get the dialog to disappear.
Looking at the code and the docs for addEventListener, I believe there should be a simple fix to this problem.
If multiple identical EventListeners are registered on the same EventTarget with the same parameters, the duplicate instances are discarded. They do not cause the EventListener to be called twice, and they do not need to be removed manually with the removeEventListener() method.
Note, however that when using an anonymous function as the handler, such listeners will NOT be identical, because anonymous functions are not identical even if defined using the SAME unchanging source-code simply called repeatedly, even if in a loop.
It looks like the root of the problem is the fact that we are using anonymous functions when adding the event listener. If we can ensure that the functions are static when the code runs again the additional event listener will be ignored since it is identical. Since this is based off behavior from rails I think it would be good to borrow/steal their implementation since it should handle these problems out of the box.
https://github.com/rails/rails/tree/master/actionview/app/assets/javascripts
- Dominant language
- Elixir
- Stars
- 467
- Forks
- 228
- Avg merge
- 1h 24m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phoenixframework/phoenix_html
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
phoenixframework/phoenix_html#445 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
phoenixframework/phoenix_html#416 · 12 comments · 1 reaction ·
All issues in phoenixframework/phoenix_html
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
phoenixframework/phoenix#6847 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
beyond-all-reason/teiserver#1584 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ash-project/ash#2954 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
membraneframework/boombox#149 ·