fix: repair persistence - safe-persist getItem now returns parsed objects, fix resetGame localStorage keys
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m22s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m22s
- safe-persist.ts: getItem now calls JSON.parse(str) so Zustand receives {state, version} envelope
- gameActions.ts: fix 5 wrong localStorage keys in createResetGame (mana→mana-storage, etc.)
- Add persistence.test.ts with 12 tests covering round-trip, key verification, and reset
- All 918 tests pass with zero regressions
This commit is contained in:
@@ -6,17 +6,24 @@ import { useManaStore } from './manaStore';
|
||||
import { useCombatStore } from './combatStore';
|
||||
import { computeDisciplineEffects } from '../effects/discipline-effects';
|
||||
|
||||
// Exact localStorage keys matching each store's persist config `name`
|
||||
const ALL_STORE_KEYS = [
|
||||
'mana-loop-game-storage',
|
||||
'mana-loop-mana',
|
||||
'mana-loop-combat',
|
||||
'mana-loop-prestige',
|
||||
'mana-loop-crafting',
|
||||
'mana-loop-attunements',
|
||||
'mana-loop-discipline-store',
|
||||
'mana-loop-ui-storage',
|
||||
] as const;
|
||||
|
||||
export const createResetGame = (set: (state: Partial<GameCoordinatorState>) => void, initialState: GameCoordinatorState) => () => {
|
||||
// Clear all persisted state
|
||||
// Clear all persisted state — must use exact keys from each store's persist config
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.removeItem('mana-loop-ui-storage');
|
||||
localStorage.removeItem('mana-loop-prestige-storage');
|
||||
localStorage.removeItem('mana-loop-mana-storage');
|
||||
localStorage.removeItem('mana-loop-combat-storage');
|
||||
localStorage.removeItem('mana-loop-game-storage');
|
||||
localStorage.removeItem('mana-loop-crafting-storage');
|
||||
localStorage.removeItem('mana-loop-attunement-storage');
|
||||
localStorage.removeItem('mana-loop-discipline-store');
|
||||
for (const key of ALL_STORE_KEYS) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
}
|
||||
|
||||
const startFloor = 1;
|
||||
|
||||
Reference in New Issue
Block a user