Skip to content

hx-swap has confusing behavior when its value is invalid #3237

@sheepman4267

Description

@sheepman4267

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions