htmx icon indicating copy to clipboard operation
htmx copied to clipboard

`hx-swap` has confusing behavior when its value is invalid

Open sheepman4267 opened this issue 10 months ago • 0 comments

Per the docs:

The hx-swap attribute allows you to specify how the response will be swapped in relative to the target of an AJAX request. If you do not specify the option, the default is htmx.config.defaultSwapStyle (innerHTML).

This makes sense.

What makes less sense to me is that it also seems to silently default to innerHTML when the value specified is invalid. As in, an element with hx-swap="gobbledygook" set would use innerHTML. To me, it seems that hx-swap="gobbledygook" is an invalid configuration, and should result in an error (or at least a warning) in the console. Falling back and performing an innerHTML swap would make sense to me, but in my opinion, there should also be an error.

Context: I just spent 2 hours trying to figure out why idiomorph wasn't doing what I expected. If hx-swap="morph:outerHTML" had produced something like htmx:swapError in my console, I would have much more quickly discovered that I had installed the idiomorph extension wrong, and that my initial setup should have worked perfectly.

sheepman4267 avatar Mar 17 '25 16:03 sheepman4267