Why
Hello. 馃憢 I've run into a situation where setting default behavior for htmx causes a weird edge case when using the SSE extension in regards to swapping of content.
How
To recreate, add a global htmx configuration as follows:
<meta name="htmx-config" content='{"defaultSwapStyle": "outerHTML"}'>
Then you can render a template with the following setup:
<figure class="device"
hx-ext="sse"
sse-connect="/preview/<%= name %>"
sse-swap="preview">
<%= image_tag "loader.svg", alt: "Loader", width: 800, height: 480 %>
</figure>
<form action="/designer" method="post" class="form">
<textarea name="template[content]"
class="source"
hx-post="/designer"
hx-trigger="load, keyup delay:200ms"
hx-swap="textContent">
<%= render :welcome %>
</textarea>
</form>
The critical piece is the use of hx-swap="textContent" in the text area. Use of textContent for swapping purposes completely fails when the global htmx configuration uses outerHTML as the default swap behavior. If you remove the global configuration, everything works properly. For some reason, the SSS extension appears to not honor the textContent swap style when the global configuration is in play.
Why
Hello. 馃憢 I've run into a situation where setting default behavior for htmx causes a weird edge case when using the SSE extension in regards to swapping of content.
How
To recreate, add a global htmx configuration as follows:
Then you can render a template with the following setup:
The critical piece is the use of
hx-swap="textContent"in the text area. Use oftextContentfor swapping purposes completely fails when the global htmx configuration usesouterHTMLas the default swap behavior. If you remove the global configuration, everything works properly. For some reason, the SSS extension appears to not honor thetextContentswap style when the global configuration is in play.