InfoQDaniel Curtis2 min readrelease notesintermediate
htmx 4.0: a Fetch-Based Rewrite, Built-In Morphing Swaps, and Explicit Attribute Inheritance
Summary
htmx 4.0 replaces XHR with fetch (enabling streaming), adds built‑in morphing swaps via idiomorph, introduces hx‑partial for multi‑target updates, makes attribute inheritance explicit with a :inherited suffix, renames several attributes/events, adds a 60 s request timeout, and ships under npm's `next` tag with a CLI upgrade checker.
- Fetch API replaces XMLHttpRequest, keeping the library ~14 KB and unlocking native response streaming.
- Morphing swaps (idiomorph) preserve DOM state (e.g., input focus) during updates.
- New `hx-partial` attribute lets a single response update multiple targets, simplifying out‑of‑band swaps.
- Attribute inheritance is opt‑in via `:inherited`; missing the suffix can silently break things like CSRF header propagation.
The fetch rewrite modernizes htmx’s transport layer, enabling streaming and smaller payloads while preserving its low‑JS philosophy. Explicit inheritance reduces accidental security regressions (e.g., CSRF token loss). Built‑in morphing improves UX without extra JavaScript. The CLI upgrade path eas…
5/10




