From e569c05fb1bd70424e0c6a9acf1086ab8a61cf1c Mon Sep 17 00:00:00 2001 From: babyboucher <48159308+babyboucher@users.noreply.github.com> Date: Tue, 14 Apr 2026 21:37:22 -0500 Subject: [PATCH] Fix muti game joining issue (#3675) If this PR fixes an issue, link it below. If not, delete these two lines. Resolves #3669 ## Description: Added a check to make sure that there is only one active lobbyHandle by checking if there has been a new event before it finished processing. ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: babyboucher --- src/client/Main.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/client/Main.ts b/src/client/Main.ts index f4fb076e9..262b07ceb 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -246,6 +246,7 @@ class Client { private storeModal: StoreModal; private tokenLoginModal: TokenLoginModal; private matchmakingModal: MatchmakingModal; + private mostRecentJoinEvent: number; private turnstileTokenPromise: Promise<{ token: string; @@ -739,6 +740,7 @@ class Client { private async handleJoinLobby(event: CustomEvent) { const lobby = event.detail; + this.mostRecentJoinEvent = event.timeStamp; if (this.usernameInput && !this.usernameInput.validateOrShowError()) { return; } @@ -757,7 +759,7 @@ class Client { if (lobby.source !== "public") { this.updateJoinUrlForShare(lobby.gameID, config); } - this.lobbyHandle = joinLobby(this.eventBus, { + const newLobbyHandle = joinLobby(this.eventBus, { gameID: lobby.gameID, serverConfig: config, cosmetics: await getPlayerCosmeticsRefs(), @@ -768,6 +770,14 @@ class Client { gameRecord: lobby.gameRecord, }); + if (this.mostRecentJoinEvent !== event.timeStamp) { + newLobbyHandle.stop(true); + console.warn("Join requested, but was superseded"); + return; + } + + this.lobbyHandle = newLobbyHandle; + this.lobbyHandle.prestart.then(() => { console.log("Closing modals"); document.getElementById("settings-button")?.classList.add("hidden");