Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Integrated Stockfish wasm #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Integrated Stockfish wasm #3
Changes from all commits
f8275deFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Init effect re-runs every render and interrupts the engine.
onMoveis supplied inline fromComputerChessBoard(onMove: () => {…}), so its identity changes on every render. BecauseComputerChessBoardre-renders roughly once per second (theuseTimercountdown updates state), this effect re-runs on every tick: it re-sendsuci/isready/ucinewgame(resetting engine state mid-game) and its cleanup postsstop, aborting any search that is in flight. The result is unstable Stockfish behavior.Stabilize the callback with a ref so initialization runs once per game:
🔧 Proposed fix
Alternatively, wrap
onMoveinuseCallbackat theComputerChessBoardcall site (Lines 31-36 ofcomputerGame.tsx), but the ref keeps the fix local to the hook.📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium
hooks/useTimer.tsx:4The timer clamps the active clock at
0but never reports timeout to the caller, so when a player's clock reaches0:00the game continues indefinitely — the interval keeps firing and the opponent's moves remain legal. This happens because the hook only tracks local display state viasetWhiteDisplayTime/setBlackDisplayTimeand returns those values, with no callback or state to signal that a flag fell. Consider exposing a timeout event (e.g., anonTimeoutcallback or a derivedtimeoutvalue in the return) so the caller can terminate the game and setgameOverInfowhen a clock hits zero.🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: MohamedSayed0573/ChessLab
Length of output: 2234
🏁 Script executed:
Repository: MohamedSayed0573/ChessLab
Length of output: 20108
🏁 Script executed:
Repository: MohamedSayed0573/ChessLab
Length of output: 6943
🏁 Script executed:
Repository: MohamedSayed0573/ChessLab
Length of output: 1883
Count down against the wall clock and expose timeout results.
setInterval(() => prev - 1000, 1000)can drift under browser throttling, and this hook stops at0without emitting a timeout. Make the countdown wall-clock based, ensure the player-game state is also updated the same way, and let the hook/consumer emit an explicit timeout win/draw status for when a side reaches zero.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium
pages/computerGame.tsx:31The
onMovecallback passed touseStockfishis created inline on every render, so each timer tick (once per second) re-runs the effect, sendsstopto Stockfish, and reinitializes the worker. Ago depth 15search that takes longer than one second is repeatedly canceled before completing, so Stockfish either plays a prematurely selected move or never moves at all. Store the callback in a ref (or memoize it withuseCallback) so timer-driven renders don't restart the worker while a search is in progress.Also found in 1 other location(s)
apps/client/src/hooks/useStockfish.tsx:46🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High
pages/computerGame.tsx:38onPieceDropdoesn't check thatchessGame.turn()matches the human player'sside, so the player can drag Stockfish's pieces whenever it's the engine's turn (e.g. immediately at game start whensideis"b", or while Stockfish is thinking), corrupting the turn sequence. Add a guard likeif (chessGame.turn() !== side) return false;at the top ofonPieceDrop.function onPieceDrop({ sourceSquare, targetSquare }: PieceDropHandlerArgs) { - if (chessGame.isGameOver()) return false; + if (chessGame.isGameOver() || chessGame.turn() !== side) return false;🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
Uh oh!
There was an error while loading. Please reload this page.