From 7a83b13faae5222e75c1cf39a08b0f487e8d17dd Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 11 Mar 2026 13:23:26 -0500 Subject: [PATCH] improve iOS Safari LiveView reliability increase longPollFallbackMs from 2500 to 5000 to prevent premature fallback on mobile networks, and add visibilitychange handler to reconnect WebSocket when returning from a backgrounded tab --- assets/js/app.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/js/app.ts b/assets/js/app.ts index c07aaebd..6db33162 100644 --- a/assets/js/app.ts +++ b/assets/js/app.ts @@ -1205,7 +1205,7 @@ const StatusTitle = { } const liveSocket = new LiveSocket("/live", Socket, { - longPollFallbackMs: 2500, + longPollFallbackMs: 5000, params: { _csrf_token: csrfToken, timezone: userTimezone }, hooks: { ...colocatedHooks, SensorChart, CopyToClipboard, ScrollToTop, AutoDismissFlash, BetaBannerDismiss, NetworkMap, SitesMap, LeafletMap, DeviceListReorder, MikrotikPortSync, GlobalSearch, GlobalSearchTrigger, DynamicFavicon, StatusTitle }, }) @@ -1266,6 +1266,15 @@ window.addEventListener("phx:download", (event: any) => { window.URL.revokeObjectURL(url) }) +// Reconnect WebSocket when returning from background (iOS Safari optimization) +document.addEventListener("visibilitychange", () => { + if (document.visibilityState === "visible") { + if (liveSocket.socket.connectionState() !== "open") { + liveSocket.socket.disconnect(() => liveSocket.socket.connect()) + } + } +}) + // connect if there are any LiveViews on the page liveSocket.connect()