Does htmx's SSE extension guarantee reconnection after browser tab restoration across all supported browsers?
0 reputation · 04 Jul 2024, 22:38 UTC
0 reputation · 04 Jul 2024, 22:38 UTC
The htmx SSE extension maintains persistent server-sent event connections for real-time updates, but its reconnection behavior after browser tab restoration or network interruption relies on the browser's native EventSource implementation combined with htmx's reconnect configuration parameter. The core documentation does not formally specify reconnection semantics, leaving developers uncertain about cross-browser consistency.
Determine whether the SSE extension provides a reliable, predictable reconnection guarantee when a backgrounded tab is restored or after transient network loss, without requiring custom heartbeat or fallback logic.
Reconnection depends on EventSource behavior, which varies across browser engines (Chrome, Firefox, Safari). The reconnect parameter accepts a millisecond value but its interaction with browser-level EventSource retry logic is not documented. Version-sensitive changes in htmx v1.9 may have altered internal handling without updated guidance.
What is the expected reconnection sequence when a tab wakes from the back-forward cache? Does the reconnect parameter override or supplement the browser's native retry interval? Which browser versions have been validated for consistent SSE restoration behavior?
31775 reputation · 05 Jul 2024, 01:16 UTC
No, the htmx SSE extension does not guarantee reconnection after a browser tab is restored (whether from background or from the back‑forward cache) across all supported browsers.
The extension relies on the native EventSource API. It only exposes a reconnect option that sets a custom retry interval passed to EventSource, but it does not intercept pagehide or pageshow events to restart the connection manually. Consequently, resumption depends entirely on how each browser’s EventSource implementation handles network loss and tab restoration.
Setting reconnect: 2000 (or any millisecond value) tells htmx to pass that value as the optional retry field when creating the EventSource. If the server does not send its own retry directive, EventSource will use that number as its base interval, but the actual back‑off algorithm (exponential in Chrome/Firefox, different in Safari) remains browser‑specific.
reconnect to a short value (e.g., 2000), and opens an SSE endpoint.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.