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.
* 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
* 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>
* 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>
* move tokenizer to parseConfig for all the things
* move sse mode logic
* upgrade all JSON.parse!
---------
Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
Implement native SSE handling with configurable stream modes (once/continuous), automatic reconnection with exponential backoff, and lifecycle events.
Streams are configured via hx-stream attribute or htmx.config.streams global defaults.
Update test infrastructure with ReadableStream-based mocking utilities.
# Conflicts:
# src/htmx.js