htmx icon indicating copy to clipboard operation
htmx copied to clipboard

htmx:beforeSwap event is not emitted for the hx-swap-oob swaps

Open vlad-tkachenko opened this issue 1 year ago • 1 comments

When response contains hx-swap-oob elements, htmx:beforeSwap event is only emitted for the main content only, while html:afterSwap events are emitted for all the swaps.

In my case I have a main content that is replaced with hx-boost and every response contains 3 additional hx-swap-oob elements to be replaced. I have both listeners for the htmx:beforeSwap and htmx:afterSwapevents and here is how the console.log statements look when request is completed:

Screenshot 2024-01-15 at 12 36 26

vlad-tkachenko avatar Jan 15 '24 10:01 vlad-tkachenko

Instead of emitting normal beforeSwap and afterSwap events the oob swaps seem to emit special events: https://github.com/bigskysoftware/htmx/blob/bedee219329117fff8d58e33678d82f7c34b08b5/src/htmx.js#L826-L835

I don't know why the afterSwap is emitted anyways.

itepastra avatar Jan 18 '24 10:01 itepastra