one
Version:
One is a new React Framework that makes Vite serve both native and web.
67 lines (65 loc) • 2.26 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: !0
});
},
__copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
return to;
};
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: !0
}), mod);
var skewProtection_exports = {};
__export(skewProtection_exports, {
isVersionStale: () => isVersionStale,
setupSkewProtection: () => setupSkewProtection
});
module.exports = __toCommonJS(skewProtection_exports);
var import_constants = require("./constants.native.js"),
import_getURL = require("./getURL.native.js"),
stale = !1,
polling = null;
function isVersionStale() {
return !!(stale || typeof window < "u" && window.__oneVersionStale);
}
function setupSkewProtection() {
if (typeof window > "u" || process.env.NODE_ENV === "development" || process.env.ONE_SKEW_PROTECTION !== "proactive") return;
var POLL_INTERVAL = 12e4,
baseUrl = (0, import_getURL.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 !== import_constants.CACHE_KEY) {
stale = !0, window.__oneVersionStale = !0, window.dispatchEvent(new CustomEvent("one-version-update", {
detail: {
version: data.version
}
}));
return;
}
} catch {}
polling = setTimeout(check, POLL_INTERVAL);
}
polling = setTimeout(check, POLL_INTERVAL);
}
//# sourceMappingURL=skewProtection.native.js.map