* 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
* 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.
* 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>
* 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>
* feat: add hx-ws WebSocket extension with accompanying tests and debug utilities.
* feat: Refine WebSocket extension initialization and processing logic, preventing re-initialization and ensuring comprehensive element handling.
* refactor: Enhance WebSocket connection handling with improved event triggering and dynamic configuration management
* refactor: Introduce dynamic configuration management for WebSocket connections, consolidating default settings into a dedicated function for improved maintainability and clarity.
* refactor: Update WebSocket extension to improve reconnection logic and dynamic configuration handling, enhancing maintainability and clarity.
* docs: Expand WebSocket extension documentation with detailed architecture, attributes, message formats, and example use cases for improved clarity and usability.
* refactor: Update WebSocket message structure to include default values for channel and format, enhancing clarity in documentation and implementation.
* feat: Add default `channel` and `format` values to WebSocket messages if not provided.
* move to registerExtension to avoid extension upgrade confusion
* Also fix window.htmx export to make modules work with extensions and add initial types file
* update docs on module use
---------
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
* use new formData(form) to capture web component inputs as well
* Handle duplicate name inputs better
* Add Tests
* restore comments
* restore default check
---------
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>