Skip to content

Fix global swap configuration conflict with local text content swap #181

@bkuhlmann

Description

@bkuhlmann

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.

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