From cf9975f50fcb8338a3adf4a770e2be6932a1d633 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Mon, 22 Jun 2026 15:26:48 -0400 Subject: [PATCH] fix(sw): skip controllerchange reload on first activation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reload should only fire when an existing SW is replaced by a new one (old → new), not when the SW activates for the first time on a fresh page load (null → first). The spurious reload on fresh loads was caused by checking unconditionally. Co-Authored-By: Claude Sonnet 4.6 --- src/routes/+layout.svelte | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 819e82be..56d32466 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -344,7 +344,12 @@ $effect(() => { // silently runs whatever JS it had at the time the SW changed. This caused IDAA and // other users to run stale code for weeks at a time across multiple deployments. // Added 2026-06-22 to close this gap. - const on_controller_change = () => window.location.reload(); + // Capture before registering — if null, this is first activation (fresh page load) + // and the reload is unnecessary since assets were already fetched without the SW. + const had_controller = !!navigator.serviceWorker.controller; + const on_controller_change = () => { + if (had_controller) window.location.reload(); + }; if ('serviceWorker' in navigator) { navigator.serviceWorker.addEventListener('controllerchange', on_controller_change); }