From fe2d1f6bc6ca34513b2d556539d712d29610e04b Mon Sep 17 00:00:00 2001 From: Refactoring Agent <[email protected]> Date: Wed, 6 May 2026 09:45:28 +0200 Subject: [PATCH] fix: guard localStorage for SSR, fix currentAction written to wrong store --- src/lib/game/stores/craftingStore.ts | 13 +++++++------ src/lib/game/stores/gameActions.ts | 14 ++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/lib/game/stores/craftingStore.ts b/src/lib/game/stores/craftingStore.ts index eeabf96..689411d 100644 --- a/src/lib/game/stores/craftingStore.ts +++ b/src/lib/game/stores/craftingStore.ts @@ -15,6 +15,7 @@ import { hasSpecial, SPECIAL_EFFECTS } from '../special-effects'; // Import other stores to access required state import { useSkillStore } from './skillStore'; import { useGameStore } from './gameStore'; +import { useCombatStore } from './combatStore'; // Import action modules import * as ApplicationActions from '../crafting-actions/application-actions'; @@ -140,8 +141,8 @@ export const useCraftingStore = create()( effects, }, }; - // Update currentAction in gameStore - useGameStore.setState({ currentAction: 'design' }); + // Update currentAction in combatStore + useCombatStore.setState({ currentAction: 'design' }); } else if (hasEnchantMastery && !state.designProgress2) { updates = { designProgress2: { @@ -167,7 +168,7 @@ export const useCraftingStore = create()( set({ designProgress2: null }); } else { set({ designProgress: null }); - useGameStore.setState({ currentAction: 'meditate' }); + useCombatStore.setState({ currentAction: 'meditate' }); } }, @@ -189,8 +190,8 @@ export const useCraftingStore = create()( set((s) => ({ enchantmentDesigns: [...s.enchantmentDesigns, design], designProgress: null, - currentAction: 'meditate' as const, })); + useCombatStore.setState({ currentAction: 'meditate' }); } }, @@ -214,7 +215,7 @@ export const useCraftingStore = create()( cancelApplication: () => { ApplicationActions.cancelApplication(set); - useGameStore.setState({ currentAction: 'meditate' }); + useCombatStore.setState({ currentAction: 'meditate' }); }, // Preparation actions @@ -232,7 +233,7 @@ export const useCraftingStore = create()( cancelPreparation: () => { PreparationActions.cancelPreparation(set); - useGameStore.setState({ currentAction: 'meditate' }); + useCombatStore.setState({ currentAction: 'meditate' }); }, // Loot inventory actions diff --git a/src/lib/game/stores/gameActions.ts b/src/lib/game/stores/gameActions.ts index 404ad72..a29141a 100644 --- a/src/lib/game/stores/gameActions.ts +++ b/src/lib/game/stores/gameActions.ts @@ -8,12 +8,14 @@ import { useCombatStore } from './combatStore'; export const createResetGame = (set: (state: any) => void, initialState: any) => () => { // Clear all persisted state - localStorage.removeItem('mana-loop-ui-storage'); - localStorage.removeItem('mana-loop-prestige-storage'); - localStorage.removeItem('mana-loop-mana-storage'); - localStorage.removeItem('mana-loop-skill-storage'); - localStorage.removeItem('mana-loop-combat-storage'); - localStorage.removeItem('mana-loop-game-storage'); + 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-skill-storage'); + localStorage.removeItem('mana-loop-combat-storage'); + localStorage.removeItem('mana-loop-game-storage'); + } const startFloor = 1;