Trigger update checks off WS reconnect, not just the hourly poll (#42)

A backend restart during a deploy kills every open WebSocket, and the
chat socket's existing reconnect-with-backoff already re-fires onopen
within seconds -- reuse that as a reliable "the server just restarted"
signal to check for a new service worker version, instead of waiting up
to an hour for UpdateBanner's poll. The hourly poll stays as a fallback.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-17 12:34:15 -06:00
co-authored by Claude Sonnet 5
parent dddda19238
commit 4b5fd3aab7
3 changed files with 32 additions and 2 deletions
+8 -2
View File
@@ -1,4 +1,5 @@
import { useRegisterSW } from 'virtual:pwa-register/react'
import { checkForUpdate, setSwRegistration } from '../lib/swUpdate'
import './UpdateBanner.css'
// The service worker (registerType: 'prompt', sw.ts) already installs and
@@ -6,7 +7,11 @@ import './UpdateBanner.css'
// never navigates, and a page only checks for a new SW on navigation by
// default, so a tab left open for hours could sit on a stale check
// indefinitely. This polls explicitly so "reload available" shows up
// without the user having to close and reopen the app first.
// without the user having to close and reopen the app first. It's now a
// fallback, not the primary trigger -- useChatSocket.ts also calls
// checkForUpdate() on every WS reconnect, which reliably fires within
// seconds of a deploy (the backend restart that ships a new version also
// kills every open WS connection) rather than waiting up to an hour.
const UPDATE_CHECK_INTERVAL_MS = 60 * 60 * 1000
export function UpdateBanner() {
@@ -16,7 +21,8 @@ export function UpdateBanner() {
} = useRegisterSW({
onRegisteredSW(_url, registration) {
if (!registration) return
setInterval(() => registration.update(), UPDATE_CHECK_INTERVAL_MS)
setSwRegistration(registration)
setInterval(checkForUpdate, UPDATE_CHECK_INTERVAL_MS)
},
})