Problem/Motivation
If there are other libraries or Javascript code that are have click listeners, the footnote click event can bubble up the DOM tree and cause errors.
Steps to reproduce
My specific case was combining this with tocbot for a table of contents. tocbot's listener received the bubbled click event, it grabbed the link's href (#footnote-1), extracted the ID (footnote-1), and passed it to its function which was generating the table of contents. That function then ran document.getElementById('footnote-1'), which returned null and caused footnotes to stop working.
Proposed resolution
Prevent bubbling by adding event.stopPropagation(); to handleFootnoteCitationClick()
This change only affects click events on elements with the class .js-footnote-citation. It doesn't affect any other clicks on the page.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2025-11-25_05-28.png | 97.09 KB | scott_euser |
Issue fork footnotes-3556642
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
scott_euser commentedComment #4
scott_euser commentedThanks @sbrockwell I tested this out and think it might need to be an opt-in (so I added that). For example if GA (via GTM) is click tracking on body, this would prevent that click event from bubbling up to the body. So sites using the dialog that happen to be doing that (probably rare, but not impossible) could possibly have a regression?
If you agree, could you retest please with my changes? Thanks!
You'll have to enable this checkbox after you pull in the latest from the MR (or use patch of it):
Comment #5
scott_euser commented@sbrockwell are the changes I made to your MR okay?
Comment #7
rduterteHi All,
I did some testing to replicate the issue. Using a simple HTML test page with a global click listener, I observed that clicking a .js-footnote-citation link causes the click event to bubble up to the global listener e.g document.addEventListener.
I applied this MR patch: https://git.drupalcode.org/project/footnotes/-/merge_requests/92.patch the event stops at the link and no longer reaches global listeners.
In my test, this resolved the issue and prevented errors. I hope this helps.
Happy to help test or review other issues as well!
Comment #9
scott_euser commentedThanks for confirming! Merged in