From acfa9d97b3e9c4dc031537ca676a09bf6590249c Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Wed, 30 Sep 2026 22:44:13 -0400 Subject: [PATCH] fix(streaming): code-review pass on the exit chord move Release a desktop claim still held at unmount, mark an unstarted chord hold with null rather than 0, and cover the Stream listener, the held-through-close latch, and escape-stack cleanup in tests. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../v2/composables/useGamepad/index.test.ts | 30 ++++++++++++++++--- .../src/v2/composables/useGamepad/index.ts | 8 ++--- frontend/src/v2/views/Player/Desktop.test.ts | 20 +++++++++++++ frontend/src/v2/views/Player/Desktop.vue | 8 ++++- frontend/src/v2/views/Player/Stream.test.ts | 21 +++++++++++++ 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/frontend/src/v2/composables/useGamepad/index.test.ts b/frontend/src/v2/composables/useGamepad/index.test.ts index dd37d3185..2935ecbd5 100644 --- a/frontend/src/v2/composables/useGamepad/index.test.ts +++ b/frontend/src/v2/composables/useGamepad/index.test.ts @@ -246,12 +246,34 @@ describe("useGamepad", () => { it("holds off while an overlay sits over the game", () => { const dialog = { close: () => {}, persistent: true }; pushEscapable(dialog); - pads = [padHolding(...CHORD)]; - stepAt(0); - stepAt(EXIT_CHORD_HOLD_MS * 2); - popEscapable(dialog); + try { + pads = [padHolding(...CHORD)]; + stepAt(0); + stepAt(EXIT_CHORD_HOLD_MS * 2); + } finally { + popEscapable(dialog); + } expect(chords).toBe(0); }); + + it("stays fired after its dialog closes while the chord is still held", () => { + const dialog = { close: () => {}, persistent: false }; + pads = [padHolding(...CHORD)]; + stepAt(0); + stepAt(EXIT_CHORD_HOLD_MS); + expect(chords).toBe(1); + + pushEscapable(dialog); + try { + stepAt(EXIT_CHORD_HOLD_MS + 100); + } finally { + popEscapable(dialog); + } + stepAt(EXIT_CHORD_HOLD_MS * 3); + stepAt(EXIT_CHORD_HOLD_MS * 5); + + expect(chords).toBe(1); + }); }); }); diff --git a/frontend/src/v2/composables/useGamepad/index.ts b/frontend/src/v2/composables/useGamepad/index.ts index 3a90accc8..cce865917 100644 --- a/frontend/src/v2/composables/useGamepad/index.ts +++ b/frontend/src/v2/composables/useGamepad/index.ts @@ -256,7 +256,7 @@ export function useGamepad() { const { setModality } = useInputModality(); let rafId = 0; let everSawPad = false; - let chordHeldSince = 0; + let chordHeldSince: number | null = null; // Cleared only on release, so a chord still held after its dialog is // cancelled doesn't reopen it. let chordFired = false; @@ -375,12 +375,12 @@ export function useGamepad() { // The game's pad gets no B, so a long Select+Start hold is the way out. if (!chordHeld) { - chordHeldSince = 0; + chordHeldSince = null; chordFired = false; } else if (!gameOwnsInput) { - chordHeldSince = 0; + chordHeldSince = null; } else if (!chordFired) { - if (!chordHeldSince) chordHeldSince = t; + chordHeldSince ??= t; if (t - chordHeldSince >= EXIT_CHORD_HOLD_MS) { chordFired = true; window.dispatchEvent(new Event("gamepad:exitchord")); diff --git a/frontend/src/v2/views/Player/Desktop.test.ts b/frontend/src/v2/views/Player/Desktop.test.ts index ff827d05d..bdc5d6f11 100644 --- a/frontend/src/v2/views/Player/Desktop.test.ts +++ b/frontend/src/v2/views/Player/Desktop.test.ts @@ -438,4 +438,24 @@ describe("Desktop claims that outlive the view", () => { expectReleasedOwnClaim(); }); + + it("hands back a claim that answers while the leave is still resolving", async () => { + let answer = (_: unknown) => {}; + mocks.claimDesktop.mockReturnValue( + new Promise((resolve) => { + answer = resolve; + }), + ); + mocks.releaseSession.mockResolvedValue({}); + const wrapper = await mountDesktop(); + + expect(await mocks.routeLeave?.()).toBe(true); + answer(CLAIM); + await flushPromises(); + wrapper.unmount(); + mounted = null; + await flushPromises(); + + expectReleasedOwnClaim(); + }); }); diff --git a/frontend/src/v2/views/Player/Desktop.vue b/frontend/src/v2/views/Player/Desktop.vue index b2afe469f..a53ca160b 100644 --- a/frontend/src/v2/views/Player/Desktop.vue +++ b/frontend/src/v2/views/Player/Desktop.vue @@ -10,7 +10,7 @@ import { RAlert, RBtn, RSpinner } from "@v2/lib"; import { useEventListener, useIntervalFn } from "@vueuse/core"; import { isAxiosError } from "axios"; -import { computed, onMounted, ref } from "vue"; +import { computed, onBeforeUnmount, onMounted, ref } from "vue"; import { useI18n } from "vue-i18n"; import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router"; import { ROUTES } from "@/plugins/router"; @@ -237,6 +237,12 @@ useEventListener(window, "pagehide", onPageHide); onMounted(() => { void openDesktop(); }); + +// A claim that answered after the leave guard let navigation through, while +// the next route was still resolving, is still held here. +onBeforeUnmount(() => { + if (holdsClaim.value) void release(); +});