fuzzyworld

word-waltz / commit

handle old storage state

881b4413aa5aab8480e83362a52d390aa71376e0 · Pavel Safronov · 2026-03-27 10:56:32 -0700 · parents a7605dfa473a

handle old storage state
 src/main.ts | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main.ts b/src/main.ts
index a859762..6902b0f 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -22,7 +22,7 @@ import { notifyMyTurn, clearNotification, registerServiceWorker, subscribeToPush
 import speakerIconUrl from './assets/speaker.png';
 import muteIconUrl from './assets/mute.png';
 import urlIconUrl from './assets/url.png';
-import { getRandomWord } from './utils/wordList.js';
+import { getRandomWord, isValidAnswer } from './utils/wordList.js';
 import type { GameState, PlayerId, Round, SoloGameState, SoloRound, PendingNotification } from './types.js';
 // Waiting status helper
 // ---------------------------------------------------------------------------
@@ -336,7 +336,15 @@ const SOLO_KEY = 'word-waltz:solo';
 function loadSoloGame(): SoloGameState | null {
     try {
         const raw = localStorage.getItem(SOLO_KEY);
-        return raw ? (JSON.parse(raw) as SoloGameState) : null;
+        if (!raw) return null;
+        const state = JSON.parse(raw) as SoloGameState;
+        // Discard games created with an old word list
+        const currentWord = state.rounds[state.currentRound]?.word;
+        if (!currentWord || !isValidAnswer(currentWord)) {
+            localStorage.removeItem(SOLO_KEY);
+            return null;
+        }
+        return state;
     } catch {
         return null;
     }