From 11f51944dfc35fcdecb2c67813a04457dbdc1a36 Mon Sep 17 00:00:00 2001 From: Ilia Denisov Date: Fri, 22 May 2026 15:56:32 +0200 Subject: [PATCH] fix(ui): register the service worker in production only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SvelteKit's automatic SW registration also runs under `vite dev`, where the worker intercepted/cached the dev-server e2e suite (42 failures). Disable auto-registration (kit.serviceWorker.register: false) and register the worker manually from the root layout guarded by `!dev`, so `vite dev` and the e2e suite run worker-free while the production build — and the PWA preview test — still install it. Co-Authored-By: Claude Opus 4.7 (1M context) --- ui/frontend/src/routes/+layout.svelte | 7 +++++++ ui/frontend/svelte.config.js | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/ui/frontend/src/routes/+layout.svelte b/ui/frontend/src/routes/+layout.svelte index bda93c4..1047743 100644 --- a/ui/frontend/src/routes/+layout.svelte +++ b/ui/frontend/src/routes/+layout.svelte @@ -4,6 +4,7 @@ import { onMount } from "svelte"; import { goto } from "$app/navigation"; import { page } from "$app/state"; + import { dev } from "$app/environment"; import { i18n } from "$lib/i18n/index.svelte"; import { session } from "$lib/session-store.svelte"; import { eventStream } from "../api/events.svelte"; @@ -21,6 +22,12 @@ onMount(() => { void session.init(); + // Production-only service-worker registration (auto-register is off + // in svelte.config.js) so `vite dev` and the dev-server e2e suite + // run without the worker intercepting requests. + if (!dev && "serviceWorker" in navigator) { + void navigator.serviceWorker.register("/service-worker.js"); + } return () => { eventStream.stop(); streamSessionId = null; diff --git a/ui/frontend/svelte.config.js b/ui/frontend/svelte.config.js index 836e7d0..e85780e 100644 --- a/ui/frontend/svelte.config.js +++ b/ui/frontend/svelte.config.js @@ -11,5 +11,11 @@ export default { fallback: "index.html", strict: true, }), + serviceWorker: { + // Registered manually in the root layout for production only. + // SvelteKit's auto-registration also runs under `vite dev`, where + // the worker would intercept and cache the dev-server e2e suite. + register: false, + }, }, };