[WIP] Fix stuck 'Waiting' state in start-game flow#1
Draft
Copilot wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.
Original prompt
Fix stuck "Waiting" state in start-game flow by clearing stale game state on disconnect. In signaling-server/server.js, when a player disconnects, if the room becomes empty, delete rooms[roomId] and gameState[roomId]. If the current game exists and the disconnected socket was the speaker, clear gameState[roomId] and emit "reset-game" to the room so a new game can start. Ensure existing room-update behavior remains. Provide minimal change, keep current start-game guard logic intact.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: can you check the code, cause after i click start its stuck for waiting
Assistant: I couldn’t access the repo via search (it appears inaccessible). Please confirm the repository is public or grant access, and tell me which branch to inspect (e.g.,
main). If you can share a link to the file where the “Start” button logic lives (or paste that snippet), I can pinpoint why it gets stuck on “waiting.”User: this repo
Assistant: Likely cause: the game never starts because the server refuses to start unless at least 2 players are in the same room, so the UI stays on “Waiting…”.
From your server code:
So if you click Start with only one player, it silently returns and nothing happens.
✅ What you should do
(Optional) Improve the UI with feedback
Right now the user gets no warning if start is blocked. I can help add a message like:
If you want, I can prepare the exact fix or even open a PR.
User: its happening even if 2 players are joined
Assistant: Most likely cause: your client is connecting to the hosted server on Render, not your local server — so the two players you joined locally never exist on the server you’re actually sending
start-gameto.In
client/script.jsthe socket points to:If you’re running the server locally (
localhost:3000), the client still sends events to Render, sostart-gamenever fires for your local players. That leaves the UI stuck on Waiting.✅ Fix (choose one)
Option A — Run everything against local server
Change this line to:
Option B — Use Render server
Make sure both players open the deployed client that connects to Render (not your local HTML file).
Quick check
Open DevTools → Console and confirm you see ✅ Connected.
If you see
❌ Disconnectedor no log at all, it’s not connecting to the correct server.If you want, tell me how you’re running the app (local vs deployed), and I’ll give the exact steps to fix it.
User: not using local server its running on vercel
Assistant: Most likely cause now: the server blocks
start-gameif a previous game exists and wasn’t markedwon, and that state is never cleared on disconnect. So if a game was started and someone left (or tab refreshed),gameState[roomId]stays stuck, and all future starts are ignored.Here’s the block that causes it:
And on disconnect, you never clear
gameState[roomId]:✅ Fix (recommended)
Clear the game if the room becomes empty or if the current speaker left. Example: