// Tombstone service worker for the site origin's root scope (`/`).
//
// The game UI used to be served at this origin's root with a
// root-scoped service worker. It now lives under `/game/` (its own
// scoped worker), and the project site served at `/` ships no service
// worker of its own. This file exists only so any lingering old
// root-scoped worker, on its next update check, replaces itself with
// this one — which unregisters itself and reloads its controlled pages
// so they fall through to the live network (the site) instead of a
// stale cache. New visitors never register it; nothing here calls
// `register`.
self.addEventListener("install", () => self.skipWaiting());

self.addEventListener("activate", (event) => {
	event.waitUntil(
		(async () => {
			await self.registration.unregister();
			const clients = await self.clients.matchAll({ type: "window" });
			for (const client of clients) {
				client.navigate(client.url);
			}
		})(),
	);
});
