Skip to content

fix: spectator chat attributed to bot, bot-turn toast shown to spectators #597

@KovalDenys1

Description

@KovalDenys1

Bugs

Two spectator bugs found while watching a Connect Four (player vs bot) game.

Bug 1 — Chat message attributed to bot

When a spectator sends a chat message, it appears in the chat attributed to the second player's name (the bot).

Root cause: sendChat() computes myName = myDisc === 1 ? p1Name : p2Name. For spectators myDisc is null, so the condition is false → always uses p2Name (bot). Same issue in Tic-Tac-Toe (mySymbol === 'X' ? xName : oName).

Bug 2 — Bot failed toast for spectators

Spectators occasionally see "Bot failed to make a move" toast even though the bot plays normally.

Root cause: useBotTurn hook has no isSpectator guard — spectators' clients trigger bot-turn API calls, compete with the real player's client (409 conflicts), and on certain error paths show the error toast.

Affected files

  • app/lobby/[code]/connect-four-page.tsx
  • app/lobby/[code]/tic-tac-toe-page.tsx
  • app/lobby/[code]/hooks/useBotTurn.ts
  • app/lobby/[code]/LobbyPageClient.tsx

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions