فهرست منبع

fix: separate localStorage per language to prevent cross-language game leaks

Storage keys are now wordle-state-en and wordle-state-ru,
so switching languages doesn't carry over guesses or game
state from the other language.
Oleg Panashchenko 1 هفته پیش
والد
کامیت
f2db4f967b
1فایلهای تغییر یافته به همراه6 افزوده شده و 3 حذف شده
  1. 6 3
      client/src/hooks/usePersistence.ts

+ 6 - 3
client/src/hooks/usePersistence.ts

@@ -1,12 +1,15 @@
 import { useState, useCallback, useEffect } from 'react';
 import { useState, useCallback, useEffect } from 'react';
 import type { PersistedState } from '@wordle/shared';
 import type { PersistedState } from '@wordle/shared';
 import { defaultPersistedState } from '@wordle/shared';
 import { defaultPersistedState } from '@wordle/shared';
+import { detectLang } from '../messages/index.js';
 
 
-const STORAGE_KEY = 'wordle-state';
+function storageKey(): string {
+  return `wordle-state-${detectLang()}`;
+}
 
 
 function loadState(): PersistedState {
 function loadState(): PersistedState {
   try {
   try {
-    const raw = localStorage.getItem(STORAGE_KEY);
+    const raw = localStorage.getItem(storageKey());
     if (raw) {
     if (raw) {
       return JSON.parse(raw) as PersistedState;
       return JSON.parse(raw) as PersistedState;
     }
     }
@@ -17,7 +20,7 @@ function loadState(): PersistedState {
 }
 }
 
 
 function saveState(state: PersistedState): void {
 function saveState(state: PersistedState): void {
-  localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
+  localStorage.setItem(storageKey(), JSON.stringify(state));
 }
 }
 
 
 export function usePersistence() {
 export function usePersistence() {