UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

46 lines (45 loc) 1.34 kB
import { CACHE_KEY } from "./constants.mjs"; import { getURL } from "./getURL.mjs"; let stale = false; let polling = null; function isVersionStale() { if (stale) return true; if (typeof window !== "undefined" && window.__oneVersionStale) return true; return false; } function setupSkewProtection() { if (typeof window === "undefined") return; if (process.env.NODE_ENV === "development") return; if (process.env.ONE_SKEW_PROTECTION !== "proactive") return; const POLL_INTERVAL = 12e4; const baseUrl = getURL(); async function check() { try { const res = await fetch(`${baseUrl}/version.json`, { headers: { "cache-control": "no-cache", pragma: "no-cache" } }); if (!res.ok) { polling = setTimeout(check, POLL_INTERVAL); return; } const data = await res.json(); if (data.version !== CACHE_KEY) { stale = true; window.__oneVersionStale = true; window.dispatchEvent(new CustomEvent("one-version-update", { detail: { version: data.version } })); return; } } catch {} polling = setTimeout(check, POLL_INTERVAL); } polling = setTimeout(check, POLL_INTERVAL); } export { isVersionStale, setupSkewProtection }; //# sourceMappingURL=skewProtection.mjs.map