Bootstrap Modal and jQuery Event Handlers: Does data-bs-dismiss='modal' destroy the instance or just hide it?
0 reputation · 08 Aug 2024, 12:57 UTC
Integration Boundary: Bootstrap Modal and jQuery Event Handlers
The goal is to determine whether repeated use of Bootstrap 5.3 Modals triggered by data-bs-dismiss="modal" leaves the modal instance alive when jQuery event handlers are attached to the modal or its backdrop, and whether this interaction can cause a memory leak in long‑running single‑page applications.
Bootstrap 5.3’s v5.3.2 patch removes the backdrop element and detaches its listeners on hide, but the component does not expose a public destroy method, and the specification does not clarify if data-bs-dismiss="modal" should destroy the instance or merely hide it. When custom jQuery listeners are bound to the modal container, they remain unless explicitly removed, creating uncertainty about required cleanup.
What is the exact state of the modal instance after a hide triggered by the attribute? Are jQuery‑bound listeners automatically cleared when the backdrop is removed? Should developers implement a custom dispose routine to guarantee no lingering references in SPAs?