bigskysoftware / idiomorph

A DOM-merging algorithm
BSD 2-Clause "Simplified" License
631 stars 31 forks source link

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

Open aral opened 4 months ago

aral commented 4 months ago

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 commented 3 months ago

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