Fix accordion re-init after HTMX outerHTML swap on repertoire page

The htmx:afterSwap handler was calling initAccordions(e.detail.target)
but after an outerHTML swap, e.detail.target references the old detached
DOM element, not the new live element. This meant accordion click
handlers were never attached to the new filter column toggles after
applying or removing a filter — breaking all subsequent interaction.

Fix: query the live DOM with document.querySelector() instead.
This commit is contained in:
Pontoporeia
2026-06-24 11:12:56 +02:00
parent ecb90ba5dd
commit bb3bb80567

View File

@@ -96,10 +96,12 @@
// Initial bind // Initial bind
initAccordions(document); initAccordions(document);
// Re-bind after HTMX swaps // Re-bind after HTMX swaps.
// Must query the live DOM — e.detail.target is the *old* detached element after outerHTML swaps.
document.body.addEventListener('htmx:afterSwap', function (e) { document.body.addEventListener('htmx:afterSwap', function (e) {
if (e.detail.target && e.detail.target.matches && e.detail.target.matches(INDEX_SEL)) { if (e.detail.target && e.detail.target.matches && e.detail.target.matches(INDEX_SEL)) {
initAccordions(e.detail.target); var liveIndex = document.querySelector(INDEX_SEL);
if (liveIndex) initAccordions(liveIndex);
} }
}); });