fix(matchmaking): reset phase synchronously to stop stale-ready fast-join
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 <noreply@anthropic.com>
This commit is contained in:
@@ -148,6 +148,14 @@ export const useOnlineStore = create<OnlineStore>((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);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user