From b12a7c7813285ea93648e76216c0b9eb26a79ee6 Mon Sep 17 00:00:00 2001 From: "soroush.asadi" Date: Sat, 20 Jun 2026 10:55:56 +0330 Subject: [PATCH] fix(matchmaking): reset phase synchronously to stop stale-ready fast-join MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Leaving a match left mm.phase stuck on "ready". On the next league tap, playLeague navigated to the matchmaking screen before svc.startMatchmaking (which awaits connect+profile) could emit "searching" — so the screen mounted with the old "ready" phase and its auto-enter effect instantly dropped the player into a stale game with no lobby. Reset matchmaking to a fresh "searching" state synchronously in the store before the async work to close the race. Co-Authored-By: Claude Sonnet 4.6 --- src/lib/online-store.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/online-store.ts b/src/lib/online-store.ts index 872029d..8499ca2 100644 --- a/src/lib/online-store.ts +++ b/src/lib/online-store.ts @@ -148,6 +148,14 @@ export const useOnlineStore = create((set, get) => ({ startMatchmaking: async (opts) => { const svc = getService(); if (mmUnsub) mmUnsub(); + // Reset to a fresh "searching" state SYNCHRONOUSLY before any async work. The + // matchmaking screen auto-enters the game when phase === "ready"; if a prior + // match left phase stuck on "ready", the screen would mount and fast-join a + // stale game before svc.startMatchmaking() (which awaits connect+profile) can + // emit "searching". Resetting here closes that race. + set({ + matchmaking: { phase: "searching", players: [], elapsedMs: 0, ranked: opts.ranked, stake: opts.stake }, + }); mmUnsub = svc.onMatchmaking((s) => set({ matchmaking: s })); await svc.startMatchmaking(opts); },