fix: handle server behavior around reconnects, fix fetching reservations

This commit is contained in:
2026-04-23 14:24:32 -04:00
Unverified
parent f11c1c7de1
commit 7f52da0d62
5 changed files with 49 additions and 9 deletions

View File

@@ -23,6 +23,8 @@ export default function PlayPage() {
role,
username,
status,
isInMatch,
shouldGoFirst,
send,
subscribe,
reconnectAttempts,
@@ -86,13 +88,25 @@ export default function PlayPage() {
}
if (status === "connected" && gamePhase === "idle") {
setGamePhase("connected");
// Mid-match reconnect can remount with phase idle while still in a match; avoid
// the pre-queue "connected" / Ready Up state until we know we are not in-game.
setGamePhase(isInMatch ? "playing" : "connected");
if (isInMatch) {
const color: 1 | 2 = shouldGoFirst ? 1 : 2;
setMyColor(color);
myColorRef.current = color;
setIsMyTurn(shouldGoFirst);
isMyTurnRef.current = shouldGoFirst;
}
}
}, [
role,
status,
router,
gamePhase,
isInMatch,
shouldRedirectToConnect,
clearRedirectFlag,
]);
@@ -102,7 +116,11 @@ export default function PlayPage() {
switch (msg.type) {
case "CONNECT_ACK":
case "RECONNECT_ACK":
setGamePhase((prev) => (prev === "idle" ? "connected" : prev));
setGamePhase((prev) => {
if (prev !== "idle") return prev;
if (isInMatch) return "playing";
return "connected";
});
break;
case "ERROR":
@@ -193,7 +211,7 @@ export default function PlayPage() {
});
return unsubscribe;
}, [resetGame, send, subscribe]);
}, [resetGame, send, subscribe, isInMatch, username]);
const handleColumnClick = useCallback(
(col: number) => {