one
Version:
One is a new React Framework that makes Vite serve both native and web.
46 lines (45 loc) • 1.36 kB
JavaScript
import { CACHE_KEY } from "./constants.native.js";
import { getURL } from "./getURL.native.js";
var stale = false;
var 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;
var POLL_INTERVAL = 12e4;
var baseUrl = getURL();
async function check() {
try {
var res = await fetch(`${baseUrl}/version.json`, {
headers: {
"cache-control": "no-cache",
pragma: "no-cache"
}
});
if (!res.ok) {
polling = setTimeout(check, POLL_INTERVAL);
return;
}
var 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 (unused) {}
polling = setTimeout(check, POLL_INTERVAL);
}
polling = setTimeout(check, POLL_INTERVAL);
}
export { isVersionStale, setupSkewProtection };
//# sourceMappingURL=skewProtection.native.js.map