import { useEffect, useState } from "react"; import { IoDownloadOutline } from "react-icons/io5"; export default function ServiceWorkerUpdateNotifier() { const [hasUpdate, setHasUpdate] = useState(false); useEffect(() => { (async () => { const registration = await navigator.serviceWorker.getRegistration(); if (!registration) { return; } registration.addEventListener( "updatefound", () => { console.debug("Service Worker update detected"); const installingWorker = registration.installing; if (!installingWorker) { return; } installingWorker.addEventListener("statechange", () => { if (installingWorker.state !== "activated") { // should maybe retry if state === "redundant" console.debug(`Service worker state changed to ${installingWorker.state}`); return; } setHasUpdate(true); }); }, { once: true }, ); })(); }, []); if (!hasUpdate) { return null; } return (
;
); }