From eaf5d897ae86cf38caf1f83230c266985797c6ef Mon Sep 17 00:00:00 2001 From: m5r Date: Mon, 27 Jun 2022 13:49:56 +0200 Subject: [PATCH] * don't mess with immutable request headers * don't mess with requests outside the app (analytics, error tracking) --- app/entry.worker.ts | 6 +++++- app/service-worker/cache-utils.ts | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/entry.worker.ts b/app/entry.worker.ts index d307a8d..f996fa2 100644 --- a/app/entry.worker.ts +++ b/app/entry.worker.ts @@ -30,7 +30,11 @@ self.addEventListener("message", (event) => { }); self.addEventListener("fetch", (event) => { - if (event.request.headers.get("Accept") === "text/event-stream") { + const isSSERequest = event.request.headers.get("Accept") === "text/event-stream"; + const isOutsideRequest = !["localhost", "dev.shellphone.app", "www.shellphone.app"].includes( + new URL(event.request.url).hostname, + ); + if (isSSERequest || isOutsideRequest) { return; } diff --git a/app/service-worker/cache-utils.ts b/app/service-worker/cache-utils.ts index 993a578..b98a5e6 100644 --- a/app/service-worker/cache-utils.ts +++ b/app/service-worker/cache-utils.ts @@ -68,7 +68,6 @@ export function fetchLoaderData(event: FetchEvent): Promise { return caches.match(event.request, { cacheName: DATA_CACHE }).then((cachedResponse) => { console.debug(`Serving data from ${cachedResponse ? "cache" : "network"}`, path); - cachedResponse?.headers.set("X-Remix-Worker", "yes"); const timestamp = lastTimeRevalidated[path] ?? 0; const diff = Date.now() - timestamp;