149 Commits

Author SHA1 Message Date
MichaelWest22
c6644aa72a
handle newContent processing of outerMorph that inserts new nodes (#3667) 2026-02-22 17:01:43 -07:00
Carson Gross
503a4d1b8a slight update to the confirm API 2026-02-22 13:21:44 -07:00
Carson Gross
93fda88ed1 handle bad scroll selectors gracefully 2026-02-22 10:11:38 -07:00
Carson Gross
eef2379c8b Handle situation when there are no extensions that add custom swaps gracefully 2026-02-22 08:50:44 -07:00
Carson Gross
f032843bde fix abort bug 2026-02-21 16:31:05 -07:00
Christian Tanul
923b022d9b
Extract SSE from core into standalone extension (#3666)
Move SSE out of htmx core into a standalone extension (hx-sse.js).

The new extension uses Fetch + ReadableStream instead of EventSource,
so it works with POST, custom headers, and cookies. Two modes:
- One-off streams: any hx-get/hx-post returning text/event-stream
- Persistent connections: hx-sse:connect with auto-reconnect

SSE events now follow the extension pattern:
- htmx:before:sse:connection / htmx:after:sse:connection
- htmx:before:sse:message / htmx:after:sse:message
- htmx:sse:error / htmx:sse:close

New features:
- hx-sse:close="eventname" to close connection on a named event
- htmx:sse:close event with reason (message, removed, ended, etc.)
- htmx:before:response core event for extension response interception
- Server retry: field updates reconnect delay per SSE spec
- Non-2xx reconnect responses fire htmx:sse:error

SSE parser improvements (spec compliance):
- Handle CRLF, CR, and LF line endings
- Strip leading BOM (U+FEFF)
- Dispatch empty data fields
- Ignore id fields containing NULL
- Process field-only lines (no colon) per spec

Docs:
- Document htmx:before:response in events, reference, building guide
- Add htmx 2.x → 4.x SSE migration guide
- Document hx-sse:close and htmx:sse:close
- Add hx-sse:connect, hx-sse:close to JetBrains web-types
- Fix stale Accept header reference in migration guide

Remove htmx.config.sse from core config tables (extension-only now).
Remove stale SSE event references from core docs.
2026-02-21 14:43:06 -07:00
MichaelWest22
093ee58bc0
handle empty non get actions (#3661) 2026-02-17 21:46:50 -07:00
Carson Gross
f3f8873f9b add a new testing API for deterministically resolved responses 2026-02-12 17:20:52 -07:00
MichaelWest22
081b82dcde
fix history restore to always use innerHTML (#3655)
* fix history restore to always use innerHTML

* avoid test breaking browser tests
2026-02-12 15:53:18 -07:00
MichaelWest22
3b2ab35019
Alpine compatibility extension (#3654)
* remove apline attributes from pre settle nodes

* simplify a little

* move to an extension

* Try applying alpine to fragments before swap

* handle morph properly

* defer count tracking

* handle child template morph and use local alpine for test reliablilty

* improve defercount

* post rebase tidy

* improve x-id and x-for handling

* patch isSoftMatch instead of removing generated id's
2026-02-12 14:27:24 -07:00
MichaelWest22
b15849a0ca
Add focus resoration support (#3645)
* Add focus resoration support

* add focusScroll support
2026-02-10 16:41:10 -07:00
MichaelWest22
cd0024e8aa
fix firefox not handling script tags in templates (#3650) 2026-02-09 02:05:40 +13:00
Carson Gross
f7d84d2058 Merge remote-tracking branch 'origin/four' into four 2026-02-02 18:35:35 -07:00
Carson Gross
ac776e121c Properly ignore form inputs on GET/DELETEs within forms. 2026-02-02 18:12:47 -07:00
Stu Kennedy
3a72a1d2a3
feat(ws): handle non-JSON messages as raw HTML with cancelable event (#3641)
* feat(ws): handle non-JSON messages as raw HTML with cancelable event

Non-JSON WebSocket messages now swap as raw HTML instead of being
dropped. Fires a cancelable htmx:ws:rawMessage event before swapping,
allowing custom handling when needed.

- If hx-target is set: swaps into target using element's swap style
- If no hx-target: uses swap:none to protect connection element,
  but hx-partial tags in payload still reach their own targets
- preventDefault() on the event skips default swap for custom handling

Replaces the old htmx:wsUnknownMessage event which only notified
but took no action on non-JSON data.

* test(ws): add tests for raw HTML message handling and cancelable event

Tests cover:
- Non-JSON messages swap as raw HTML into hx-target
- swap:none used when no hx-target (protects connection element)
- hx-partial tags in raw messages still reach their targets
- htmx:ws:rawMessage event fires with message data
- preventDefault() on rawMessage cancels default swap

---------

Co-authored-by: Stu Kennedy <stu@stukennedy.com>
2026-01-29 13:44:24 -07:00
Christian Tanul
d99095eb3c
Fix iOS Safari SSE disconnect on background (#3634) (#3640)
* Close SSE stream on visibility change to fix iOS Safari background disconnect (#3634)

iOS Safari silently kills TCP connections when the app is backgrounded,
leaving SSE streams dead with no error event. The new `closeOnHide`
config option proactively cancels the stream reader when the page
becomes hidden and reconnects when visible again (requires
`reconnect: true`).

Also renames `pauseInBackground` to `closeOnHide` across source, docs,
types, and tests to reflect the new disconnect/reconnect behavior
(previously it only paused processing).

* Improve SSE closeOnHide with reconnectRequested flag and cancellable backoff

- Create reader outside __parseSSE and pass as argument
- Add reconnectRequested flag so visibility reconnects skip backoff delay
- Symmetric visibility handler: cancel on hidden, reconnect on visible
- Cancellable backoff delay via delayCanceller so tab return is instant
2026-01-29 13:15:13 -07:00
MichaelWest22
7759d402f8
Update ws extension to use htmx.swap (#3638)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2026-01-29 13:14:51 -07:00
Christian Tanul
18a05bc70b
Fix morph error with empty id attributes (#3639)
skip empty id attributes in morph persistent ID matching
2026-01-30 01:44:54 +13:00
Stu Kennedy
77cece0a1e
Add tests for WebSocket script tag processing (#3637) 2026-01-27 14:39:44 -07:00
Carson Gross
18f936d811 trigger htmx:before:request and htmx:after:request on target element, added events.js for testing events
fixes https://github.com/bigskysoftware/htmx/issues/3628
2026-01-20 14:25:54 -07:00
Anton Lorani
54bf849fc9
Trims only the first leading space in a SSE field value (#3588) (#3589) 2026-01-20 14:06:19 -07:00
MichaelWest22
720fe71ecd
fix document fragment parsing of full page responses for live script support (#3629)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2026-01-19 17:48:16 -07:00
MichaelWest22
7dbb8acfa6
Upsert swap extension (#3595)
* add upsert swap extension

* improve upsert

* simplify upsert to not use morph

* add doco

* Add hx-upsert tag support as well

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-31 12:47:08 -07:00
MichaelWest22
77e5c4724b
Handle newContent properly in insertContent (#3607)
* handle newContent processing in other swap styles

* Handle outerMorph newContent processing by adding target to newContent so it will be processed as well. also simplified textContent swaps

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-30 07:54:52 -07:00
MichaelWest22
095db015a4
Push response url (#3608)
* handle response url from redirects in push Url true

* add test

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-30 07:53:58 -07:00
MichaelWest22
9bab1d6704
handle no id found with hx-preserve (#3610)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-30 07:53:03 -07:00
Carson Gross
0dea4bc308 Merge branch 'four' into feature/settle-restoration
# Conflicts:
#	src/htmx.js
2025-12-24 13:40:25 -07:00
Stu Kennedy
37cf0e8c6c
WebSocket Extension (hx-ws) Improvements (#3592)
* refactor: Enhance WebSocket extension with URL normalization, improved request management, and refined message handling for better reliability and clarity.

feat: Add manual WebSocket server script and enhance WebSocket documentation with detailed message formats and connection management improvements.

feat: Include event type in WebSocket messages and update documentation for message format

* refactor: Update WebSocket extension to connect immediately by default, enhance documentation on connection triggers, and improve message handling examples.

* feat: Introduce URL validation for WebSocket send attributes to ensure proper connection handling and prevent non-URL markers from being processed.
2025-12-19 11:42:36 -07:00
MichaelWest22
56e6810284
add textContent swap style (#3593)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-19 11:39:09 -07:00
Carson Gross
2f816af101 move swap delay and settle delay inside of __insertContent (makes more sense to me here) 2025-12-18 11:18:41 -07:00
Carson Gross
c603dc9543 Merge remote-tracking branch 'origin/four' into four 2025-12-15 14:42:07 -07:00
Carson Gross
ab862afe74 finish up hx-sync 2025-12-15 14:41:45 -07:00
MichaelWest22
4403f8eff6
optimize hx-vals and headers async with a callback and fix ws async (#3581)
optimize hx-vals and headers async with a callback and fix ws async hx-vals

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-11 11:04:08 -07:00
MichaelWest22
40ecbfd6b6
bug morph cleanup of textNodes should work (#3584)
* bug morph cleanup of textNodes should work

* use firstchild check instead

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-12 01:26:41 +13:00
MichaelWest22
f0ff590fb4
handle returning this from findAllExt for any inheritance level (#3579)
* change thisElt to thisAttr to simplify

* Handle returning this properlty at any level

* add this wrapper for clarity

* move to callback instead

* rename to eltCollector

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-09 09:23:30 -07:00
Carson Gross
b2f4abae76 add hx-disable.js test and fix logic to be the same as hx-indicator 2025-12-07 10:22:35 -07:00
Carson Gross
cab78da9ee make hx-headers dynamic like hx-vals and port 2.x tests 2025-12-07 10:08:51 -07:00
Carson Gross
36acc330f4 add sanity tests for core attributes 2025-12-07 09:31:58 -07:00
Carson Gross
c96179f3e7 port 2.0 tests and fix hx-include overriding 2025-12-07 09:24:23 -07:00
MichaelWest22
3b21c64193
improve parseConfig and append to allow joining json for hx-vals (#3577)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-07 09:00:47 -07:00
MichaelWest22
101110521a
handle transition overrides on oob/partial (#3570)
* handle transition overrides on oob/partial

* Handle swap dealys properly for transition true/false and respect main swap transition and swap delay.

* swapDelay let

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-06 07:35:56 -07:00
Carson Gross
9146038611 Merge remote-tracking branch 'origin/four' into four 2025-12-05 11:01:46 -07:00
Carson Gross
259ab69b0f fix hx-indicator 2025-12-05 11:01:37 -07:00
MichaelWest22
a5f48867b0
Morph skip support for web components (#3573)
* add morphSkip configs to allow web component no morph override options

* add tests

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-04 11:46:48 -07:00
MichaelWest22
0bb59973f8
fix hx-validate to respect noValidate and validate inputs outside of … (#3562)
fix hx-validate to respect noValidate and validate inputs outside of just forms

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-04 11:45:04 -07:00
MichaelWest22
ab37e06ccc
fix missing target/swap via envelope and fix re-connection tests (#3571)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-04 11:39:14 -07:00
MichaelWest22
7e7592aeb8
fix bug with empty response after partial removal detection (#3569)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-03 13:21:18 -07:00
MichaelWest22
22205ce3f4
Add mergeConfig support and remove + hx-config merging (#3561)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-03 13:21:01 -07:00
MichaelWest22
1ca51d2fde
implement advanced hx-boost overrides (#3549)
* implement advanced hx-boost overrides

* fix hx-boost false and change to override hx-* attributes

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-12-03 13:20:30 -07:00
MichaelWest22
0c8dff8e4d
add findall and fix find (#3555)
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-11-25 18:36:18 -07:00