Skip to content

Commit

Permalink
Merge pull request #1657 from geyserfund/sajal/gys-8712-i-am-not-gett…
Browse files Browse the repository at this point in the history
…ing-refresh-banner-that-there-is-a-geyser

fix: add refetch service worker on load
  • Loading branch information
sajald77 authored Sep 26, 2024
2 parents 4742534 + 29bd405 commit b39f5ad
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/context/serviceWorkerUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ export const ServiceWorkerProvider = ({ children }: { children: React.ReactNode
} = useRegisterSW({
onRegisteredSW(swUrl, r) {
if (r) {
setInterval(async () => {
if (!(!r.installing && navigator)) return

if ('connection' in navigator && !navigator.onLine) return

const refetch = async () => {
const resp = await fetch(swUrl, {
cache: 'no-store',
headers: {
Expand All @@ -56,6 +52,15 @@ export const ServiceWorkerProvider = ({ children }: { children: React.ReactNode
},
}).catch((error) => console.log('error', error))
if (resp?.status === 200) await r.update()
}

refetch()
setInterval(async () => {
if (!(!r.installing && navigator)) return

if ('connection' in navigator && !navigator.onLine) return

refetch()
}, REFETCH_SW_INTERVAL_MS)
}
},
Expand Down

0 comments on commit b39f5ad

Please sign in to comment.