"use client"; import { useEffect, useState } from "react"; import { RefreshCw } from "lucide-react"; /** * PEP-114: a page opened before the site was updated may press buttons the new server doesn't * know — nothing happens and nothing is said. This watches the server's boot id (once a minute * and when the tab comes back) and asks to reload when it changed. Never reloads by itself: the * person may be in the middle of typing. */ export function VersionWatch({ boot }: { boot: string }) { const [stale, setStale] = useState(false); useEffect(() => { let alive = true; const check = async () => { try { const r = await fetch("/api/health", { cache: "no-store" }); const now = ((await r.json()) as { boot?: string }).boot; if (alive && now && now !== boot) setStale(true); } catch { /* offline or restarting: the next check will tell */ } }; const t = setInterval(check, 60_000); const onVisible = () => document.visibilityState === "visible" && void check(); document.addEventListener("visibilitychange", onVisible); window.addEventListener("focus", onVisible); return () => { alive = false; clearInterval(t); document.removeEventListener("visibilitychange", onVisible); window.removeEventListener("focus", onVisible); }; }, [boot]); if (!stale) return null; return (
Peppa FACTORY обновилась. Обновите страницу — иначе кнопки на ней могут не сработать.
); }