Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/src/main.tsx
iris fd51cbd19d swarm-ui: pages that only display start from the answer they last saw, then refresh behind it
usePolled takes a cache key: it saves each answer in localStorage and starts
from the saved one, so opening the agents, alerts, builds, review runs or hives
view shows the last data at once and the refresh spinner marks the update. A
saved answer is dropped after a day, when it was saved by another build of the
UI, at log out (a new onLogout of the shared user menu) and when the gateway
ends the login (a new onSessionEnded of the session guard). Pages with an
editor (schedules, notification flows, broadcast) do not use it.
2026-11-05 23:14:25 +01:00

27 lines
1 KiB
TypeScript

import { render } from "preact";
import { App } from "./App.js";
import { clearAnswers } from "./ui/polled/answer-cache.js";
import { installSessionGuard, onSessionEnded } from "./ui/session/session.js";
// Before anything fetches: a 401 that means "log in again" reloads the page.
onSessionEnded(clearAnswers);
installSessionGuard();
const root = document.getElementById("root");
if (root) {
render(<App />, root);
}
// PWA installability — see sw.js's own top comment for
// what it does and does not cache. Feature-detected: older browsers
// without service-worker support just don't get the install affordance,
// nothing here depends on it existing.
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("/sw.js").catch((err: unknown) => {
// Never surfaces to the operator — a failed SW registration means
// "not installable this session," not "the app is broken."
console.error("swarm-ui: service worker registration failed", err);
});
});
}