Skip to content

Commit

Permalink
Merge pull request #149 from supabase-community/fix/service-worker-ha…
Browse files Browse the repository at this point in the history
…rd-reload

Fix service worker unavailable after hard reload
  • Loading branch information
gregnr authored Dec 10, 2024
2 parents 33e3467 + b0e4f1d commit 2771c3b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/web/components/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ const queryClient = new QueryClient()

async function registerServiceWorker() {
try {
await navigator.serviceWorker.register('/sw.mjs')
const reg = await navigator.serviceWorker.getRegistration()

// If this was a hard refresh (no controller), browsers will disable service workers
// We should soft reload the page to ensure the service worker is active
if (reg?.active && !navigator.serviceWorker.controller) {
window.location.reload()
}
await navigator.serviceWorker.register('/sw.mjs', { scope: '/' })
} catch (error) {
console.error('Failed to register service worker', error)
}
Expand Down

0 comments on commit 2771c3b

Please sign in to comment.