From 7f17f4b31e1a762f40e61074e1a92d670429715a Mon Sep 17 00:00:00 2001 From: David Alvarez Date: Sat, 23 May 2026 19:29:07 +0200 Subject: [PATCH] Fix Stop + broken buttons: use location.reload() which preserves hash but fully unloads page, killing workers and audio. Revert pathname routing (unnecessary). --- frontend/src/App.svelte | 34 ++++------------------------------ frontend/src/pages/Play.svelte | 7 ++++--- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index c758a97..a535a82 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -8,28 +8,7 @@ let route = $state("/"); let gameId = $state(null); - function parseRoute() { - // Check pathname first (full page navigations from Stop button) - const path = window.location.pathname.replace(/\/+$/, "") || "/"; - if (path !== "/") { - const parts = path.split("/").filter(Boolean); - if (parts.length >= 2) { - const [routeName, routeId] = parts; - if (routeName === "game" || routeName === "play") { - route = "/" + routeName; - gameId = routeId; - // Sync the hash so hash-based links still work - window.history.replaceState(null, "", "#/" + routeName + "/" + routeId); - return; - } - } - // Unknown path, reset to home - route = "/"; - gameId = null; - return; - } - - // Fall back to hash-based routing (SPA transitions) + function parseHash() { const hash = window.location.hash.slice(1) || "/"; const parts = hash.split("/").filter(Boolean); if (parts.length === 0 || (parts.length === 1 && parts[0] === "")) { @@ -49,15 +28,10 @@ // Listen for hash changes and page loads $effect(() => { - parseRoute(); - const handler = () => parseRoute(); + parseHash(); + const handler = () => parseHash(); window.addEventListener("hashchange", handler); - // Also listen for popstate (for browser back/forward) - window.addEventListener("popstate", handler); - return () => { - window.removeEventListener("hashchange", handler); - window.removeEventListener("popstate", handler); - }; + return () => window.removeEventListener("hashchange", handler); }); diff --git a/frontend/src/pages/Play.svelte b/frontend/src/pages/Play.svelte index 1520822..bc5732d 100644 --- a/frontend/src/pages/Play.svelte +++ b/frontend/src/pages/Play.svelte @@ -65,9 +65,10 @@ } function stopEmulator() { - // Navigate to an actual server path to force full page unload - // which kills Web Workers, AudioContexts, and WASM threads - window.location.href = `/game/${game.id}`; + // Force full page reload which terminates all workers, AudioContexts + // and WASM threads. Hash is preserved so the SPA routes correctly. + window.location.hash = `#/game/${game.id}`; + window.location.reload(); } $effect(() => { load(); });