bigskysoftware / bigskysoftware/htmx-extensions
SSE doesn't work with custom `handleSwap` extensions (i.e. idiomorph)
- Dominant language
- JavaScript
- Stars
- 284
- Forks
- 88
- PR merge metrics
- No merged PRs in 30d
Description
The SSE extension does not work with HTMX extensions that define a `handleSwap` method. This means that e.g. Idiomorph can't be used with SSE with the standard syntax:
```html
```
The reason is that `sse.js` calls the `api.swap` method without providing `swapOptions.contextElement`. Without this defined, the downstream call to `getExtensions` in `swapWithStyle` returns an empty list and the swapping strategy is degraded to the standard `htmx.config.defaultSwapStyle` (innerHTML).
The fix seems to be as simple as making this change on line 283 in `sse.js`.
```diff
- api.swap(target, content, swapSpec)
+ api.swap(target, content, swapSpec, { contextElement: elt })
```
I will get a PR up asap.
Contributor guide
Research direction
Start in sse.js around line 283, where the SSE extension calls api.swap, and compare the call with the documented custom handleSwap and Idiomorph example. Reproduce the provided HTML scenario, then verify that the swap receives the context needed to select the extension strategy and that the Idiomorph swap occurs instead of the default innerHTML swap.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100