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 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);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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(); });
|
||||
|
||||
Reference in New Issue
Block a user