Fix(ServiceWorker): Mitigate persistent TypeError by disabling auto-registration

- Mitigation: Disabled `serviceWorker.register` in `svelte.config.js` to stop the loop of `TypeError` during script evaluation.
- Debug Tool: Preserved the `fix-sw` cache clearing utility by moving it to `src/routes/testing/fix-sw/+page.svelte` for future investigation.
- Service Worker: Simplified `src/service-worker.js` to a minimal "Hello World" state and removed the problematic `.ts` version.
- Cleanup: Minor formatting adjustment in `ae_events_functions.ts`.
- Docs: Updated `TODO.md` and `GEMINI.md` to reflect the mitigation and planned follow-up.
This commit is contained in:
Scott Idem
2026-01-21 16:49:33 -05:00
parent 09c7d2440a
commit 8fae3aa89a
6 changed files with 87 additions and 74 deletions

View File

@@ -1,77 +1,13 @@
/// <reference types="@sveltejs/kit" />
import { build, files, version } from '$service-worker';
/// <reference lib="webworker" />
// Create a unique cache name for this deployment
const CACHE = `cache-${version}`;
console.log('Service Worker: Hello from the simplified JS worker!');
const ASSETS = [
...build, // the app itself
...files // everything in `static`
];
self.addEventListener('install', (event) => {
// Create a new cache and add all files to it
async function addFilesToCache() {
const cache = await caches.open(CACHE);
await cache.addAll(ASSETS);
}
event.waitUntil(addFilesToCache());
self.addEventListener('install', () => {
console.log('Service Worker: Installed');
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
// Delete old caches
async function deleteOldCaches() {
for (const key of await caches.keys()) {
if (key !== CACHE) await caches.delete(key);
}
}
event.waitUntil(deleteOldCaches());
self.addEventListener('activate', () => {
console.log('Service Worker: Activated');
});
self.addEventListener('fetch', (event) => {
// ignore POST requests etc
if (event.request.method !== 'GET') return;
async function respond() {
const url = new URL(event.request.url);
const cache = await caches.open(CACHE);
// `build`/`files` can always be served from the cache
if (ASSETS.includes(url.pathname)) {
const response = await cache.match(url.pathname);
if (response) {
return response;
}
}
// for everything else, try the network first, but fallback to the cache if we're offline
try {
const response = await fetch(event.request);
// if we're offline, fetch can return a value that is not a response
// instead of throwing - check it is a real response
if (response instanceof Response) {
if (response.status === 200) {
cache.put(event.request, response.clone());
}
return response;
}
throw new Error('invalid response');
} catch (err) {
const response = await cache.match(event.request);
if (response) {
return response;
}
// if there is no match, the throw will propagate to the browser, which
// will show its default offline page.
throw err;
}
}
event.respondWith(respond());
});