From e5308ac239b88809e5ca7af8327a314dd72e4b4b Mon Sep 17 00:00:00 2001 From: n8n-gitea Date: Wed, 6 May 2026 20:48:14 +0200 Subject: [PATCH] Fix GrimoireTab loading state and spireMode tab switching - FIX 6: GrimoireTab now properly handles loading state and shows message when no grimoire spells are available - FIX 7: Added spireMode store read and useEffect to switch to spire tab when enterSpireMode() is called --- src/app/page.tsx | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 6a4c214..9ef6bb2 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -66,23 +66,26 @@ const TabLoadingFallback = () =>
// ============================================================================ function GrimoireTab() { - // Handle SSR - dont access SPELLS_DEF during server-side rendering - // Use state and useEffect to only access on client-side - const [grimoireSpells, setGrimoireSpells] = useState([]); - - useEffect(() => { - // Only access SPELLS_DEF on client-side + const [grimoireSpells, setGrimoireSpells] = useState(() => { if (typeof window !== 'undefined' && SPELLS_DEF) { - const filtered = Object.values(SPELLS_DEF || {}).filter((s: any) => s.grimoire); - // eslint-disable-next-line react-hooks/set-state-in-effect - setGrimoireSpells(filtered); + return Object.values(SPELLS_DEF).filter((s: any) => s.grimoire); } - }, []); + return []; + }); + const loaded = grimoireSpells.length > 0 || (typeof window !== 'undefined' && !SPELLS_DEF); - if (!grimoireSpells.length) { + if (!loaded) { return
Loading grimoire...
; } + if (grimoireSpells.length === 0) { + return ( +
+ No grimoire spells available yet. Defeat guardians to unlock spells. +
+ ); + } + const availablePages = Math.ceil(grimoireSpells.length / 12); return ( @@ -145,6 +148,7 @@ export default function ManaLoopGame() { const maxFloorReached = useCombatStore((s) => s.maxFloorReached); const spells = useCombatStore((s) => s.spells); + const spireMode = useCombatStore((s) => s.spireMode); const gameOver = useUIStore((s) => s.gameOver); @@ -206,7 +210,14 @@ export default function ManaLoopGame() { }, [initGame]); const [mounted, setMounted] = useState(false); - useEffect(() => { setMounted(true); }, []); + useEffect(() => { setMounted(true); }, []); // eslint-disable-line react-hooks/set-state-in-effect + + // React to spireMode changes from combat store + useEffect(() => { + if (spireMode) { + setActiveTab('spire'); // eslint-disable-line react-hooks/set-state-in-effect + } + }, [spireMode]); // Conditional returns AFTER all hooks if (gameOver) {