From 6ecde4bf92185fc9265965b040eef8a8410679c0 Mon Sep 17 00:00:00 2001 From: "Kevin B." Date: Mon, 23 Nov 2026 23:03:38 -0500 Subject: [PATCH] address comment --- .../useTranscodePlaybackStart.test.ts | 22 +++++++++++++++---- .../player/useTranscodePlayback.ts | 5 +---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/frontend/src/composables/player/__tests__/useTranscodePlaybackStart.test.ts b/frontend/src/composables/player/__tests__/useTranscodePlaybackStart.test.ts index 49cf786b3..d8c71a1b4 100644 --- a/frontend/src/composables/player/__tests__/useTranscodePlaybackStart.test.ts +++ b/frontend/src/composables/player/__tests__/useTranscodePlaybackStart.test.ts @@ -197,7 +197,7 @@ describe("useTranscodePlayback start and offer ownership", () => { }); describe("route change during a standalone start", () => { - it("ends on the newer mode in the state and the URL once the route settles", async () => { + async function runStartWithRouteChanges(routeModes: string[]) { getSessions.mockResolvedValue({ sessions: [] }); const route = reactive({ query: {} as Record, path: "/files/a.mp4", hash: "" }); replace.mockImplementation((async (to: { query: Record }) => { @@ -212,21 +212,35 @@ describe("useTranscodePlayback start and offer ownership", () => { const pending = transcode.startTranscodePlayback({ mode: "quality" }); await vi.waitFor(() => expect(hoisted.starts).toHaveLength(1)); - route.query = { transcode: "balanced" }; - await nextTick(); + for (const mode of routeModes) { + route.query = { transcode: mode }; + await nextTick(); + } hoisted.gate = null; gate.resolve(); await pending; - await vi.waitFor(() => expect(hoisted.starts).toHaveLength(2)); await vi.waitFor(() => expect(transcode.transcodeSwitchInProgress.value).toBe(false)); await new Promise((resolve) => { setTimeout(resolve, 20); }); + return { transcode, route }; + } + + it("ends on the newer mode in the state and the URL once the route settles", async () => { + const { transcode, route } = await runStartWithRouteChanges(["balanced"]); expect(hoisted.starts.map((start) => start.mode)).toEqual(["quality", "balanced"]); expect(transcode.transcodeMode.value).toBe("balanced"); expect(route.query.transcode).toBe("balanced"); }); + + it("keeps the start mode when the route returns to it before the start finishes", async () => { + const { transcode, route } = await runStartWithRouteChanges(["balanced", "quality"]); + + expect(hoisted.starts.map((start) => start.mode)).toEqual(["quality"]); + expect(transcode.transcodeMode.value).toBe("quality"); + expect(route.query.transcode).toBe("quality"); + }); }); describe("playback URL after a managed switch", () => { diff --git a/frontend/src/composables/player/useTranscodePlayback.ts b/frontend/src/composables/player/useTranscodePlayback.ts index 98d6e5ed2..f65b1dd59 100644 --- a/frontend/src/composables/player/useTranscodePlayback.ts +++ b/frontend/src/composables/player/useTranscodePlayback.ts @@ -1394,10 +1394,7 @@ export function useTranscodePlayback(options: UseTranscodePlaybackOptions) { if (urlTranscode === parseTranscodeModeFromQuery(oldQuery)) { return; } - const requestedMode = urlTranscode || "native"; - if (requestedMode !== transcodeMode.value) { - void switchTranscodeMode(requestedMode); - } + void switchTranscodeMode(urlTranscode || "native"); }, );