import { useEffect } from 'react' /** * Registers the service worker, `src/sw.js`, which keeps the build's files and shows an offline * page when the app is opened without a connection. Only a production build has one, so in * development this removes any left by `pnpm preview` on the same port. */ export function useServiceWorker() { useEffect(() => { if (!('serviceWorker' in navigator)) return if (import.meta.env.PROD) { navigator.serviceWorker.register('/sw.js').catch(() => { // The app works the same without it, only not offline. }) return } void navigator.serviceWorker.getRegistrations().then((registrations) => { for (const registration of registrations) void registration.unregister() }) }, []) }