add template wrapping support to ws extension #172
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
npm run test) and verified that it succeeded