Skip to content

Commit 3428597

Browse files
Copilotmgierschdev
andcommitted
Fix pipeline error: handle null game state during build
Co-authored-by: mgierschdev <62764972+mgierschdev@users.noreply.github.com>
1 parent cceeb5a commit 3428597

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

frontend/src/app/_client_components/ChessGameWrapper.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
'use client';
22

3-
import React, {useState} from 'react';
3+
import React, {useState, useEffect} from 'react';
44
import Chessboard from "@/app/_client_components/Chessboard";
55
import RightSidePanel from "@/app/_client_components/RightSidePanel";
6+
import {ChessService} from "@/app/_services/ChessService";
7+
import {ChessGame} from "@/app/_models/ChessGame";
68

7-
export default function ChessGameWrapper({gameInfo}: any) {
9+
const gameService = new ChessService();
10+
11+
export default function ChessGameWrapper({gameInfo: initialGameInfo}: {gameInfo: ChessGame | null}) {
812
const [isBotMode, setIsBotMode] = useState(false);
13+
const [gameInfo, setGameInfo] = useState<ChessGame | null>(initialGameInfo);
14+
15+
// If no initial game info, fetch it on the client side
16+
useEffect(() => {
17+
if (!gameInfo) {
18+
gameService.getChessGame().then(info => {
19+
if (info) {
20+
setGameInfo(info);
21+
}
22+
}).catch(error => {
23+
console.error("Failed to fetch game info:", error);
24+
});
25+
}
26+
}, [gameInfo]);
27+
28+
// Show loading state if game info isn't available yet
29+
if (!gameInfo) {
30+
return (
31+
<>
32+
<div className="left-panel">
33+
<div>Loading chess game...</div>
34+
</div>
35+
<div className="right-panel">
36+
<div>Loading...</div>
37+
</div>
38+
</>
39+
);
40+
}
941

1042
return (
1143
<>

frontend/src/app/page.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ import {ChessGame} from "@/app/_models/ChessGame";
66
import {metadata} from "@/app/layout";
77
import ChessGameWrapper from "@/app/_client_components/ChessGameWrapper";
88

9+
// Force dynamic rendering to avoid build-time fetch issues
10+
export const dynamic = 'force-dynamic';
911

1012
export default async function Home() {
1113
let title: 'Chess';
1214
let description: 'Chess Engine';
1315
let gameService: ChessService = new ChessService();
14-
let gameInfo: ChessGame = await gameService.getChessGame();
16+
let gameInfo: ChessGame | null = null;
17+
18+
try {
19+
gameInfo = await gameService.getChessGame();
20+
} catch (error) {
21+
console.error("Failed to fetch initial game state:", error);
22+
// gameInfo will remain null, client components will handle it
23+
}
24+
1525
let currentDate = new Date();
1626

1727
return (

0 commit comments

Comments
 (0)