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); },