idiomorph icon indicating copy to clipboard operation
idiomorph copied to clipboard

morph:<expr> not usable when using hx-swap-oob with htmx WebSocket extension

Open aral opened this issue 1 year ago • 1 comments

The issue with hx-swap properties not being available in hx-swap-oob (https://github.com/bigskysoftware/htmx/issues/2308) also affects idiomorph.

Specifically, the following syntax cannot be used:

hx-swap-oob='morph:<expr>'

Use case: I was just trying to make a markdown preview updated via WebSocket scroll into view to show the latest change after the content has been morphed and I can’t.

aral avatar Feb 22 '24 11:02 aral

So the fix for this that I implemented in my fork of htmx-2 (which has the hx-swap-oob normalisation PR merged in so it differs from current htmx-2 a bit), was essentially to special-case idiomorph:

(!swapStyle.startsWith('morph:') && swapStyle.indexOf(':') > 0)

at the equivalent of the following line:

https://github.com/bigskysoftware/htmx/blob/bf692737011b40316397d55c3ee756fde6c502cf/src/htmx.js#L1417

This leaves the selector alone and allows it to be parsed properly by idiomorph.

Not making a pull request for this at the moment as it would make more sense to wait for https://github.com/bigskysoftware/htmx/issues/2308 to be resolved and then do so.

You can see the change in my fork of htmx-2 at: https://codeberg.org/kitten/app/commit/5ee6bf76393445fa8b3fb68295430402b75ae0e1

aral avatar Mar 27 '24 19:03 aral