* 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>
* 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
This update introduces a new function, processScriptTags, which ensures that script tags within the content are properly executed after being swapped. The function replaces old script elements with new ones, preserving their attributes and content. This enhancement improves the handling of dynamic content in the htmx framework.
* 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>
* 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>
* 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.