20 lines
611 B
TypeScript
20 lines
611 B
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
|
|
/** Registers the service worker for PWA install / offline shell. */
|
|
export function PwaRegister() {
|
|
useEffect(() => {
|
|
if (typeof window === "undefined" || !("serviceWorker" in navigator)) return;
|
|
const onLoad = () => {
|
|
navigator.serviceWorker.register("/sw.js").catch(() => {
|
|
/* ignore — private mode / insecure context */
|
|
});
|
|
};
|
|
if (document.readyState === "complete") onLoad();
|
|
else window.addEventListener("load", onLoad);
|
|
return () => window.removeEventListener("load", onLoad);
|
|
}, []);
|
|
|
|
return null;
|
|
}
|