Skip to content

Conversation

@MichaelWest22
Copy link
Contributor

@MichaelWest22 MichaelWest22 commented Jul 21, 2025

Description

This possible change implements tag wrapping option for web socket message responses. Right now if you return several elements to swap in via web socket extensions oob swap method in a single message then they can cause issues if the tag types are not compatible. Users can work around the issue by just splitting their backend response into mulitple messages. But if you provide a response with a div and an inner table element type as an example, then they will cause issues parsing as a valid fragment causing confusion and lost content.

This change allows you to respond with the same troublesome tables workarounds that hx-swap-oob has documented already in a ws response message.

It works by handing all content inside templates just like normal htmx does and it still allows existing use cases where template tags could have an id or hx-swap-oob element on the template tag which in the old version would have just oob swapped in the template element itself into the page. So we are able to retain full backwards compatibility with old template tag handling while supporting processing the contents of empty template tags that would have failed to be processed at all before.

Corresponding issue:
bigskysoftware/htmx#3316

Testing

Added tests to confirm template encapsulation works as expected and support for swapping in template tags with id or hx-swap-oob attributes still works as before.

Checklist

  • I have read the contribution guidelines
  • I ran the test suite locally (npm run test) and verified that it succeeded

@netlify
Copy link

netlify bot commented Jul 21, 2025

Deploy Preview for htmx-extensions canceled.

Name Link
🔨 Latest commit 8e3936b
🔍 Latest deploy log https://app.netlify.com/projects/htmx-extensions/deploys/687daa157b9a030008bff369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant