diff --git a/src/client/Main.ts b/src/client/Main.ts index dc3fb8332..bd73b5f46 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -791,32 +791,26 @@ class Client { window.location.href = "/"; } - // Handle requeue parameter for ranked matchmaking - const searchParams = new URLSearchParams(window.location.search); - if (searchParams.has("requeue")) { - // Remove only the requeue parameter, preserving other params and hash - searchParams.delete("requeue"); - const newUrl = - window.location.pathname + - (searchParams.toString() ? "?" + searchParams.toString() : "") + - window.location.hash; - history.replaceState(null, "", newUrl); - // Wait for matchmaking button to be defined, then trigger its click handler. - customElements.whenDefined("matchmaking-button").then(() => { - const matchmakingButton = document.querySelector( - "matchmaking-button button", - ) as HTMLButtonElement | null; - if (matchmakingButton) { - matchmakingButton.click(); - } else { - console.warn( - "Requeue requested, but matchmaking button not found in DOM.", - ); - } - }); + if (this.consumeRequeueUrl()) { + document.dispatchEvent(new CustomEvent("open-matchmaking")); } } + private consumeRequeueUrl(): boolean { + const searchParams = new URLSearchParams(window.location.search); + if (!searchParams.has("requeue")) { + return false; + } + + searchParams.delete("requeue"); + const newUrl = + window.location.pathname + + (searchParams.toString() ? `?${searchParams.toString()}` : "") + + window.location.hash; + history.replaceState(null, "", newUrl); + return true; + } + private async handleJoinLobby(event: CustomEvent) { const lobby = event.detail; this.mostRecentJoinEvent = event.timeStamp;