UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

47 lines (46 loc) • 1.7 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); //#region src/ui/version-check.ts /** * The soft-refresh poller (atomic-deploys 10): a browser-side loop fetching * the host's `/.well-known/version` and reporting when the served deploy * fingerprint differs from the one this document was rendered from. No live * container swap — the banner decides whether to reload (old bytes are * retained, so a reload is always safe). Polling pauses while the document * is hidden and reports at most once. */ const DEFAULT_POLL_INTERVAL_MS = 6e4; function startVersionWatch(input) { const intervalMs = input.intervalMs ?? DEFAULT_POLL_INTERVAL_MS; const fetchImpl = input.fetchImpl ?? globalThis.fetch; const doc = input.documentRef ?? document; const endpoint = input.endpoint ?? "/.well-known/version"; let reported = false; let timer = null; const poll = async () => { if (reported) return; try { const response = await fetchImpl(endpoint, { headers: { accept: "application/json" } }); if (!response.ok) return; const body = await response.json(); if (body.fingerprint && body.fingerprint !== input.currentFingerprint) { reported = true; input.onNewVersion(); } } catch {} }; const tick = () => { if (doc.visibilityState !== "visible") return; poll(); }; timer = setInterval(tick, intervalMs); const onVisibility = () => tick(); doc.addEventListener("visibilitychange", onVisibility); return { stop: () => { if (timer) clearInterval(timer); timer = null; doc.removeEventListener("visibilitychange", onVisibility); } }; } //#endregion exports.startVersionWatch = startVersionWatch; //# sourceMappingURL=version-check.cjs.map