Fix Stop + broken buttons: use location.reload() which preserves hash but fully unloads page, killing workers and audio. Revert pathname routing (unnecessary).
This commit is contained in:
+4
-30
@@ -8,28 +8,7 @@
|
|||||||
let route = $state("/");
|
let route = $state("/");
|
||||||
let gameId = $state(null);
|
let gameId = $state(null);
|
||||||
|
|
||||||
function parseRoute() {
|
function parseHash() {
|
||||||
// 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)
|
|
||||||
const hash = window.location.hash.slice(1) || "/";
|
const hash = window.location.hash.slice(1) || "/";
|
||||||
const parts = hash.split("/").filter(Boolean);
|
const parts = hash.split("/").filter(Boolean);
|
||||||
if (parts.length === 0 || (parts.length === 1 && parts[0] === "")) {
|
if (parts.length === 0 || (parts.length === 1 && parts[0] === "")) {
|
||||||
@@ -49,15 +28,10 @@
|
|||||||
|
|
||||||
// Listen for hash changes and page loads
|
// Listen for hash changes and page loads
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
parseRoute();
|
parseHash();
|
||||||
const handler = () => parseRoute();
|
const handler = () => parseHash();
|
||||||
window.addEventListener("hashchange", handler);
|
window.addEventListener("hashchange", handler);
|
||||||
// Also listen for popstate (for browser back/forward)
|
return () => window.removeEventListener("hashchange", handler);
|
||||||
window.addEventListener("popstate", handler);
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener("hashchange", handler);
|
|
||||||
window.removeEventListener("popstate", handler);
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -65,9 +65,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stopEmulator() {
|
function stopEmulator() {
|
||||||
// Navigate to an actual server path to force full page unload
|
// Force full page reload which terminates all workers, AudioContexts
|
||||||
// which kills Web Workers, AudioContexts, and WASM threads
|
// and WASM threads. Hash is preserved so the SPA routes correctly.
|
||||||
window.location.href = `/game/${game.id}`;
|
window.location.hash = `#/game/${game.id}`;
|
||||||
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => { load(); });
|
$effect(() => { load(); });
|
||||||
|
|||||||
Reference in New Issue
Block a user