bigskysoftware / bigskysoftware/htmx

hx-swap-oob cannot parse a selector containing a space

Open
#4,029 2 comments 0 reactions 1 assignee Claimed by @1cg View on GitHub
htmx 4
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

In htmx 4, `hx-swap-oob` drops the legacy colon form when the value contains a space:

```js
// __createOOBTask
if (oobValue !== "true" && oobValue && !oobValue.includes(" ")) {
```

The value then goes to `__parseSwapSpec`, which mis-parses it:

```
__parseSwapSpec("beforeend:#table tbody") -> {style:"innerHTML", beforeend:"#table", tbody:true}
__parseSwapSpec("innerHTML:global #oob-target") -> {style:"innerHTML", innerHTML:"global", "#oob-target":true}
__parseSwapSpec("innerHTML:#legacy") -> {style:"innerHTML", innerHTML:"#legacy"}
```

The swap style is wrong and no target survives, so the swap is a silent no-op. Verified end to end: `hx-swap-oob="innerHTML:#outer div"` leaves the target unchanged.

`beforeend:#table tbody` is the documented example in `www/src/content/reference/01-attributes/14-hx-swap-oob.md`, under "Using alternate swap strategies".

This also blocks the `global ` selector prefix, because that prefix needs a space. Two of the three shadow root cases from #2846 cannot be ported to htmx 4 until this is fixed. The third was ported in 2db5aaca.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.