From 581720635189b2236b6eaca6099e9827e5e33deb Mon Sep 17 00:00:00 2001
From: Refactoring Agent <[email protected]>
Date: Sun, 3 May 2026 12:58:50 +0200
Subject: [PATCH] fix: resolve SSR build error with GrimoireTab
- Fix GrimoireTab to handle SSR safely (SPELLS_DEF undefined during server-side rendering)
- Use useState and useEffect to only access constants on client-side
- Build now succeeds consistently
---
src/app/page.tsx | 40 +++++++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/src/app/page.tsx b/src/app/page.tsx
index 188115d..2f9fc47 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -65,7 +65,22 @@ const TabLoadingFallback = () =>
// ============================================================================
function GrimoireTab() {
- const grimoireSpells = Object.values(SPELLS_DEF).filter((s: any) => s.grimoire);
+ // 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
+ if (typeof window !== 'undefined' && SPELLS_DEF) {
+ const filtered = Object.values(SPELLS_DEF).filter((s: any) => s.grimoire);
+ setGrimoireSpells(filtered);
+ }
+ }, []);
+
+ if (!grimoireSpells.length) {
+ return Loading grimoire...
;
+ }
+
const availablePages = Math.ceil(grimoireSpells.length / 12);
return (
@@ -131,7 +146,7 @@ export default function ManaLoopGame() {
const gameOver = useUIStore((s) => s.gameOver);
- // Computed effects from upgrades and equipment
+ // Derived state
const upgradeEffects = getUnifiedEffects({
skillUpgrades,
skillTiers,
@@ -139,7 +154,6 @@ export default function ManaLoopGame() {
equipmentInstances: {}
});
- // Derived stats
const maxMana = computeMaxMana({
skills,
prestigeUpgrades,
@@ -192,14 +206,14 @@ export default function ManaLoopGame() {
}, [gameLoop]);
// Conditional returns AFTER all hooks
- if (typeof window === 'undefined') {
- return Loading...
;
- }
-
if (gameOver) {
return ;
}
+ if (typeof window === 'undefined') {
+ return Loading...
;
+ }
+
return (
@@ -216,10 +230,10 @@ export default function ManaLoopGame() {
{/* Main Content */}
-
@@ -242,7 +256,7 @@ export default function ManaLoopGame() {
}>
-
+
@@ -260,7 +274,7 @@ export default function ManaLoopGame() {
}>
-
+