bigskysoftware / bigskysoftware/htmx

Events htmx:afterRequest / htmx:afterOnLoad not fired in some cases

Open
#2,547 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

### Problem

The `htmx:afterRequest` and `htmx:afterOnLoad` events are not being fired when the DOM no longer contains the element nor any of its hierarchy.

### Background

I have a popup action menu powered by [tippy](https://atomiks.github.io/tippyjs/v6/getting-started/) that dynamically positions some buttons. These buttons cause htmx requests.

![2024-05-15_09-13-52](https://github.com/bigskysoftware/htmx/assets/14830/01a64032-96fa-4f54-b2a3-9b442dca27b7)

By the time the HTMX request is complete, the entire dom subtree of that menu (including the trigger button) have been removed from the DOM.

This results in `htmx:afterRequest` and `htmx:afterOnLoad` events not being triggered.

### Debugging

![image](https://github.com/bigskysoftware/htmx/assets/14830/ec2cce0c-8730-4640-a727-e60411998e2a)

Indeed, the trigger's parent hierarchy bottoms (tops?) out without getting to ``.
![2024-05-15_09-11-32](https://github.com/bigskysoftware/htmx/assets/14830/ab337664-b746-448e-834d-4efa868fdb4d)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.