Skip to content

SSE doesn't work with custom handleSwap extensions (i.e. idiomorph) #164

@FrLars21

Description

@FrLars21

The SSE extension does not work with HTMX extensions that define a handleSwap method. This means that e.g. Idiomorph can't be used with SSE with the standard syntax:

<main hx-ext="morph">
<div hx-ext="sse" sse-connect="/event-stream" sse-close="close" sse-swap="message" hx-swap="morph" hx-target="#to-be-swapped">
</main>

The reason is that sse.js calls the api.swap method without providing swapOptions.contextElement. Without this defined, the downstream call to getExtensions in swapWithStyle returns an empty list and the swapping strategy is degraded to the standard htmx.config.defaultSwapStyle (innerHTML).

The fix seems to be as simple as making this change on line 283 in sse.js.

- api.swap(target, content, swapSpec)
+ api.swap(target, content, swapSpec, { contextElement: elt })

I will get a PR up asap.

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