htmx-extensions icon indicating copy to clipboard operation
htmx-extensions copied to clipboard

sse-swap improvement

Open zanadoman opened this issue 1 year ago • 1 comments

Hi! In SSE extension it would be nice to have an option to specify a swapping strategy for sse-swap. With this improvement in hand it would be easy to stream back updates from the server for the users and use the data of the events as content. Thanks! :)

zanadoman avatar Oct 30 '24 07:10 zanadoman

@zanadoman I've recently tried using htmx-sse in a simple chat app, and I've noticed how I'm unable to render the event data. I've tried using attributes:

data-hx-trigger="sse:message"
data-hx-swap="beforeend"
data-hx-target="#message-list"

But this doesnt trigger the swap. Am I correct to assume that this is not possible to implement with htmx attributes and should be done with JS, like:

document.addEventListener('htmx:sseMessage', (event) => {
    if (event.detail.type === 'message') {
        document.querySelector('#message-list').insertAdjacentHTML('beforeend', event.detail.data);
    }
});

Is your proposal related to this issue, or am I misunderstanding?

ilyapetrovMO avatar Jun 16 '25 10:06 ilyapetrovMO