From 3dc268df889ee1d71005ea8c8a02cd9ead0b8674 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 17:54:40 -0500 Subject: [PATCH 01/11] fix(web): stop settings pages from saving changes the admin can't see Several settings pages hid a field when the setting that controls it changed, but kept the field's unsaved edit. The save bar counted it and Save wrote it. - Storage (admin and setup wizard): the link-mode settings stay in view while they hold an edit. - Setup wizard Connect apps: a typed Jellyfin address stays in view after Jellyfin is turned off. - Playback: the device picker, Buffer ahead, and the lower-version preference stay in view while they hold an edit; saved device paths keep their rows. - Compatibility: Jellyfin Web's switch-off is staged only with a real API switch-off and is taken back by any other flip. - Redis: switching it off with no saved URL drops what was typed, and the switch follows REDIS_URL once the environment takes over. Co-Authored-By: Claude Opus 5.5 --- .../CompatibilityProxiesSettings.tsx | 8 +- .../pages/admin-settings/PlaybackSettings.tsx | 25 ++++-- .../pages/admin-settings/RedisGroup.test.tsx | 76 +++++++++++++++++++ web/src/pages/admin-settings/RedisGroup.tsx | 10 +++ .../admin-settings/StorageSettings.test.tsx | 33 ++++++++ .../pages/admin-settings/StorageSettings.tsx | 49 +++++++----- .../pages/setup-wizard/steps/ConnectStep.tsx | 4 +- .../pages/setup-wizard/steps/StorageStep.tsx | 16 +++- 8 files changed, 190 insertions(+), 31 deletions(-) create mode 100644 web/src/pages/admin-settings/RedisGroup.test.tsx diff --git a/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx b/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx index 7ef22409cf..de3eeaf7d3 100644 --- a/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx +++ b/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx @@ -221,10 +221,16 @@ export default function CompatibilityProxiesSettings() { const publicURL = form.getValue("jellyfin_compat.public_url"); const serverID = form.getValue("jellyfin_compat.server_id"); + // Switching the API off also turns Jellyfin Web off, as the server's own + // Jellyfin settings endpoint does. That edit has no field on this page, so + // it is staged only with a switch-off that is itself a change, and any + // other flip takes it back rather than leave a change the admin can't see. const setJellyfinAPIEnabled = (value: string) => { form.setValue("jellyfin_compat.enabled", value); - if (value === "false") { + if (value === "false" && form.getPersistedValue("jellyfin_compat.enabled") !== "false") { form.setValue("jellyfin_compat.web_enabled", "false"); + } else { + form.resetValue("jellyfin_compat.web_enabled"); } }; const installJellyfinWeb = () => { diff --git a/web/src/pages/admin-settings/PlaybackSettings.tsx b/web/src/pages/admin-settings/PlaybackSettings.tsx index dc90c256f7..3066bfdee0 100644 --- a/web/src/pages/admin-settings/PlaybackSettings.tsx +++ b/web/src/pages/admin-settings/PlaybackSettings.tsx @@ -78,7 +78,12 @@ export default function PlaybackSettings() { const hwDevice = form.getValue("playback.hw_device"); const hwDeviceEnv = form.envVar("playback.hw_device"); const selectedDevices = parseHWDeviceList(hwDevice); - const deviceRows = buildHWDeviceRows(hwDetection.data, hwDevice); + // Saved paths keep their rows when the draft drops them, so switching off a + // device that detection doesn't list leaves its row in view to undo. + const deviceRows = buildHWDeviceRows( + hwDetection.data, + `${hwDevice},${form.getPersistedValue("playback.hw_device")}`, + ); const detectedPaths = deviceRows.filter((row) => row.detected).map((row) => row.path); // Balancing is QSV/VAAPI-only: NVENC addresses GPUs by CUDA index/UUID, so // the multi-select picker is hidden for it (the server uses the first @@ -86,7 +91,11 @@ export default function PlaybackSettings() { const isNvenc = hwAccel === "nvenc" || (hwAccel === "auto" && hwDetection.data?.resolved === "nvenc"); const inventoriesDiverge = nodeInventoriesDiverge(hwDetection.data); - const showDevicePicker = hwAccel !== "none" && !isNvenc && deviceRows.length > 0; + // A device choice staged before switching acceleration keeps the picker in + // view, so Save never writes a value the admin can't see. + const showDevicePicker = + deviceRows.length > 0 && + ((hwAccel !== "none" && !isNvenc) || form.isDirty("playback.hw_device")); const nodes = useAdminNodes(); const trickplayExecution = @@ -133,8 +142,12 @@ export default function PlaybackSettings() { const anyDirty = (keys: readonly string[]) => keys.some((key) => isDirty(key)); const allRestart = (keys: readonly string[]) => keys.every((key) => restartKeys.has(key)); - const throttleOn = form.getValue("enable_transcode_throttle") === "true"; - const allow4KTranscode = form.getValue("allow_4k_transcode") === "true"; + // Each of these rows also stays in view while it holds an unsaved edit. + const showThrottleSeconds = + form.getValue("enable_transcode_throttle") === "true" || isDirty("transcode_throttle_seconds"); + const showPreferLower = + form.getValue("allow_4k_transcode") === "true" || + isDirty("playback.prefer_lower_version_transcode"); // Every advanced transcoding key has one row, except the device picker, // which renders only when it applies. const transcodingAdvancedCount = TRANSCODING_ADVANCED_KEYS.length - (showDevicePicker ? 0 : 1); @@ -279,7 +292,7 @@ export default function PlaybackSettings() { onChange={(v) => form.setValue("allow_4k_transcode", v)} restartRequired={restartKeys.has("allow_4k_transcode")} /> - {allow4KTranscode && ( + {showPreferLower && ( form.setValue("enable_transcode_throttle", v)} restartRequired={restartKeys.has("enable_transcode_throttle")} /> - {throttleOn && ( + {showThrottleSeconds && ( ({ + sensitiveStatus: { + current: {} as { + configured: string[]; + managed_by_env: string[]; + managed_by_env_vars?: Record; + }, + }, +})); + +vi.mock("@/hooks/queries/admin/settings", () => ({ + // The snapshot never carries the URL; whether one is saved comes from the + // protected-credential status. + useAdminServerSettings: () => ({ data: { "redis.db": "" }, isLoading: false }), + useAdminSensitiveStatus: () => ({ data: sensitiveStatus.current, isError: false }), + useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), + useCheckAdminSettingsConnection: () => ({ mutateAsync: vi.fn(), isPending: false }), +})); + +function Harness() { + const form = useSettingsForm({ keys: REDIS_KEYS }); + return ( + <> + false }} + secrets={{ keepSaved: form.resetValue, setSecret: form.setValue, disabled: false }} + /> +

{`${form.dirtyCount} staged`}

+ + ); +} + +describe("RedisGroup", () => { + beforeEach(() => { + sensitiveStatus.current = { configured: [], managed_by_env: [] }; + }); + + it("stages nothing when Use Redis goes on and back off with no saved URL", async () => { + render(); + const useRedis = screen.getByRole("switch", { name: "Use Redis" }); + + await userEvent.click(useRedis); + await userEvent.type(screen.getByLabelText("Connection URL"), "redis://cache:6379"); + await userEvent.click(useRedis); + + expect(useRedis).not.toBeChecked(); + expect(screen.getByText("0 staged")).toBeInTheDocument(); + }); + + it("shows the connection REDIS_URL sets once it takes over a staged switch-off", async () => { + sensitiveStatus.current = { configured: ["redis.url"], managed_by_env: [] }; + const { rerender } = render(); + await userEvent.click(screen.getByRole("switch", { name: "Use Redis" })); + expect(screen.queryByLabelText("Connection URL")).not.toBeInTheDocument(); + + sensitiveStatus.current = { + configured: ["redis.url"], + managed_by_env: ["redis.url"], + managed_by_env_vars: { "redis.url": "REDIS_URL" }, + }; + rerender(); + + expect(screen.getByRole("switch", { name: "Use Redis" })).toBeChecked(); + expect(screen.getByLabelText("Connection URL")).toBeInTheDocument(); + }); +}); diff --git a/web/src/pages/admin-settings/RedisGroup.tsx b/web/src/pages/admin-settings/RedisGroup.tsx index a1b9086903..8ae86067f5 100644 --- a/web/src/pages/admin-settings/RedisGroup.tsx +++ b/web/src/pages/admin-settings/RedisGroup.tsx @@ -50,6 +50,9 @@ export function RedisGroup({ setLastDirtyCount(form.dirtyCount); if (form.dirtyCount === 0) setEnabledOverride(null); } + // Once REDIS_URL sets the connection the switch is locked, so a choice + // made before it took over no longer applies. + if (urlEnv && enabledOverride !== null) setEnabledOverride(null); const enabled = enabledOverride ?? (redisUrl.trim() !== "" || configured); // URL edits go through the page's editors, which drop a keystroke that // arrives while a save is in flight. @@ -97,6 +100,13 @@ export function RedisGroup({ return; } setEnabledOverride(false); + // With no saved URL there is nothing to switch off: drop what was + // typed, since the fields that showed it are about to hide. + if (!configured) { + form.resetValue("redis.url"); + form.resetValue("redis.db"); + return; + } stageRedisUrl(form, ""); }} disabled={secrets.disabled} diff --git a/web/src/pages/admin-settings/StorageSettings.test.tsx b/web/src/pages/admin-settings/StorageSettings.test.tsx index 4da84af5a0..8f7cd93ac0 100644 --- a/web/src/pages/admin-settings/StorageSettings.test.tsx +++ b/web/src/pages/admin-settings/StorageSettings.test.tsx @@ -1348,4 +1348,37 @@ describe("StorageSettings", () => { ); }); }); + + describe("leaving Cloudflare token links", () => { + beforeEach(() => { + realForm.enabled = true; + serverSettings.current = { + "artwork.storage_backend": "s3", + "s3.public_url_auth": "presigned", + }; + sensitiveStatus.current = { configured: [], managed_by_env: [] }; + }); + + afterEach(() => { + realForm.enabled = false; + }); + + it("keeps a typed token secret in view after switching back to signed links", async () => { + render(); + + const publicGroup = within(screen.getByRole("group", { name: "Public storage" })); + const linkMode = publicGroup.getByRole("combobox", { + name: "How asset links are authorized", + }); + await userEvent.click(linkMode); + await userEvent.click(screen.getByRole("option", { name: "Cloudflare signed token" })); + await userEvent.click(publicGroup.getByRole("button", { name: /Advanced/ })); + await userEvent.type(publicGroup.getByLabelText("Token Secret"), "secret"); + await userEvent.click(linkMode); + await userEvent.click(screen.getByRole("option", { name: "Signed links (recommended)" })); + + expect(screen.getByText("1 unsaved change")).toBeInTheDocument(); + expect(publicGroup.getByLabelText("Token Secret")).toHaveValue("secret"); + }); + }); }); diff --git a/web/src/pages/admin-settings/StorageSettings.tsx b/web/src/pages/admin-settings/StorageSettings.tsx index e29ab4cef0..1dcc9da807 100644 --- a/web/src/pages/admin-settings/StorageSettings.tsx +++ b/web/src/pages/admin-settings/StorageSettings.tsx @@ -59,15 +59,17 @@ const PUBLIC_S3_KEYS = [ "s3.public_token_ttl", ]; -// Shown only for the link modes that use them, behind public storage's -// Advanced disclosure. -const PUBLIC_S3_ADVANCED_KEYS = [ - "s3.public_read_endpoint", +// The Cloudflare token settings, shown only for that link mode. +const PUBLIC_S3_TOKEN_KEYS = [ "s3.public_token_secret", "s3.public_token_param", "s3.public_token_ttl", ]; +// Shown only for the link modes that use them, behind public storage's +// Advanced disclosure. +const PUBLIC_S3_ADVANCED_KEYS = ["s3.public_read_endpoint", ...PUBLIC_S3_TOKEN_KEYS]; + // Changing any of these moves where cached artwork objects live. Once artwork // has been stored in S3, direct settings writes are rejected and this page // routes the edit through the managed storage transition flow instead. @@ -271,11 +273,14 @@ function S3Group({ // Everything that reaches the bucket is shown. Only public storage has an // Advanced tier: the CDN address and the Cloudflare token settings, which - // exist only for the link modes that use them. - const advancedCount = - scope === "public" - ? (urlAuth !== "presigned" ? 1 : 0) + (urlAuth === "cloudflare_token" ? 3 : 0) - : 0; + // show for the link modes that use them, and while they hold an unsaved + // edit, so Save never writes a value the admin can't see. + const showReadEndpoint = + scope === "public" && (urlAuth !== "presigned" || form.isDirty("s3.public_read_endpoint")); + const showTokenSettings = + scope === "public" && + (urlAuth === "cloudflare_token" || countDirty(form, PUBLIC_S3_TOKEN_KEYS) > 0); + const advancedCount = (showReadEndpoint ? 1 : 0) + (showTokenSettings ? 3 : 0); const advancedChanged = countDirty(form, PUBLIC_S3_ADVANCED_KEYS); async function handleCheckConnection() { @@ -431,21 +436,23 @@ function S3Group({ count={advancedCount} forceOpen={advancedChanged > 0} > - form.setValue("s3.public_read_endpoint", v)} - restartRequired={restartKeys.has("s3.public_read_endpoint")} - managedByEnv={form.envVar("s3.public_read_endpoint")} - /> - {urlAuth === "cloudflare_token" && ( + {showReadEndpoint && ( + form.setValue("s3.public_read_endpoint", v)} + restartRequired={restartKeys.has("s3.public_read_endpoint")} + managedByEnv={form.envVar("s3.public_read_endpoint")} + /> + )} + {showTokenSettings && ( <> {/* Cloudflare token auth requires this secret, so a clear only - saves alongside a switch back to another mode — the one - order that works, since the field is hidden in those modes. + saves alongside a switch back to another mode. The staged + clear keeps these rows in view after that switch. */} form.setValue("jellyfin_compat.enabled", v)} managedByEnv={form.envVar("jellyfin_compat.enabled")} /> - {jellyfinEnabled ? ( + {/* An address typed before turning Jellyfin off stays in view, so + Continue never saves a value the admin can't see. */} + {jellyfinEnabled || form.isDirty("jellyfin_compat.public_url") ? ( `s3.${prefix}_${name}`; const urlAuth = form.getValue(key("url_auth")) || "presigned"; + // Link-mode settings show for the modes that use them, and while they hold + // an unsaved edit, so Continue never saves a value the admin can't see. + const showReadEndpoint = urlAuth !== "presigned" || form.isDirty("s3.public_read_endpoint"); + const showTokenSettings = + urlAuth === "cloudflare_token" || PUBLIC_S3_TOKEN_KEYS.some(form.isDirty); return ( <> - {urlAuth !== "presigned" ? ( + {showReadEndpoint ? ( ) : null} - {urlAuth === "cloudflare_token" ? ( + {showTokenSettings ? ( <> Date: Fri, 20 Nov 2026 18:13:57 -0500 Subject: [PATCH 02/11] fix(web): mark kept rows and keep only the edited ones Review follow-ups for the hidden-draft fix: - A link-mode setting the selected mode doesn't use stays only while it holds an edit, row by row, rather than keeping the whole Cloudflare group in view. - A row kept in view for an unsaved edit after its switch or mode would hide it carries the existing unsaved-change dot. SecretField forwards that marker. - The device picker builds rows from the saved list first and orders a toggle by the rows, so switching a device back on restores the saved order instead of leaving a reordered list staged. Co-Authored-By: Claude Opus 5.5 --- web/src/components/settings/SecretField.tsx | 4 + .../pages/admin-settings/PlaybackSettings.tsx | 29 +++-- .../pages/admin-settings/StorageSettings.tsx | 114 ++++++++++-------- .../pages/setup-wizard/steps/ConnectStep.tsx | 8 +- .../pages/setup-wizard/steps/StorageStep.tsx | 83 +++++++------ 5 files changed, 129 insertions(+), 109 deletions(-) diff --git a/web/src/components/settings/SecretField.tsx b/web/src/components/settings/SecretField.tsx index 8b79a4539e..ba8448b00a 100644 --- a/web/src/components/settings/SecretField.tsx +++ b/web/src/components/settings/SecretField.tsx @@ -39,6 +39,8 @@ export interface SecretFieldProps { hint?: string; /** Extra line under the description, e.g. a save error for this field. */ status?: ReactNode; + /** Marks the row as holding an unsaved change, as `SettingField` does. */ + dirty?: boolean; disabled?: boolean; restartRequired?: boolean; /** The environment variable that sets this secret; disables the control. */ @@ -67,6 +69,7 @@ export function SecretField({ cleared = false, hint, status, + dirty, disabled: disabledProp = false, restartRequired = false, managedByEnv, @@ -104,6 +107,7 @@ export function SecretField({ row.detected).map((row) => row.path); + const deviceOrder = deviceRows.map((row) => row.path); // Balancing is QSV/VAAPI-only: NVENC addresses GPUs by CUDA index/UUID, so // the multi-select picker is hidden for it (the server uses the first // configured entry). @@ -142,12 +143,12 @@ export default function PlaybackSettings() { const anyDirty = (keys: readonly string[]) => keys.some((key) => isDirty(key)); const allRestart = (keys: readonly string[]) => keys.every((key) => restartKeys.has(key)); - // Each of these rows also stays in view while it holds an unsaved edit. - const showThrottleSeconds = - form.getValue("enable_transcode_throttle") === "true" || isDirty("transcode_throttle_seconds"); - const showPreferLower = - form.getValue("allow_4k_transcode") === "true" || - isDirty("playback.prefer_lower_version_transcode"); + // Each of these rows also stays in view, marked as changed, while it holds + // an unsaved edit after its switch is turned off. + const throttleOn = form.getValue("enable_transcode_throttle") === "true"; + const throttleSecondsKept = !throttleOn && isDirty("transcode_throttle_seconds"); + const allow4KTranscode = form.getValue("allow_4k_transcode") === "true"; + const preferLowerKept = !allow4KTranscode && isDirty("playback.prefer_lower_version_transcode"); // Every advanced transcoding key has one row, except the device picker, // which renders only when it applies. const transcodingAdvancedCount = TRANSCODING_ADVANCED_KEYS.length - (showDevicePicker ? 0 : 1); @@ -292,9 +293,10 @@ export default function PlaybackSettings() { onChange={(v) => form.setValue("allow_4k_transcode", v)} restartRequired={restartKeys.has("allow_4k_transcode")} /> - {showPreferLower && ( + {(allow4KTranscode || preferLowerKept) && ( form.setValue("enable_transcode_throttle", v)} restartRequired={restartKeys.has("enable_transcode_throttle")} /> - {showThrottleSeconds && ( + {(throttleOn || throttleSecondsKept) && ( 0); - const advancedCount = (showReadEndpoint ? 1 : 0) + (showTokenSettings ? 3 : 0); + // exist only for the link modes that use them. A row the selected mode + // doesn't use stays, marked as changed, while it holds an unsaved edit, so + // Save never writes a value the admin can't see. + const linkModeUses = (advancedKey: string) => + advancedKey === "s3.public_read_endpoint" + ? urlAuth !== "presigned" + : urlAuth === "cloudflare_token"; + const keptForEdit = (advancedKey: string) => + !linkModeUses(advancedKey) && form.isDirty(advancedKey); + const showsAdvanced = (advancedKey: string) => + scope === "public" && (linkModeUses(advancedKey) || form.isDirty(advancedKey)); + const advancedCount = PUBLIC_S3_ADVANCED_KEYS.filter(showsAdvanced).length; const advancedChanged = countDirty(form, PUBLIC_S3_ADVANCED_KEYS); async function handleCheckConnection() { @@ -436,9 +438,10 @@ function S3Group({ count={advancedCount} forceOpen={advancedChanged > 0} > - {showReadEndpoint && ( + {showsAdvanced("s3.public_read_endpoint") && ( )} - {showTokenSettings && ( - <> - {/* - Cloudflare token auth requires this secret, so a clear only - saves alongside a switch back to another mode. The staged - clear keeps these rows in view after that switch. - */} - secrets.keepSaved("s3.public_token_secret")} - onClear={() => secrets.clearSaved("s3.public_token_secret")} - cleared={form.isClearStaged("s3.public_token_secret")} - onChange={(v) => secrets.setSecret("s3.public_token_secret", v)} - hint={t("web.admin.settings.storage.s3.tokenSecretHint")} - disabled={secrets.disabled} - restartRequired={restartKeys.has("s3.public_token_secret")} - managedByEnv={form.envVar("s3.public_token_secret")} - /> - form.setValue("s3.public_token_param", v)} - restartRequired={restartKeys.has("s3.public_token_param")} - managedByEnv={form.envVar("s3.public_token_param")} - /> - form.setValue("s3.public_token_ttl", v)} - restartRequired={restartKeys.has("s3.public_token_ttl")} - managedByEnv={form.envVar("s3.public_token_ttl")} - /> - + {/* + Cloudflare token auth requires this secret, so a clear only + saves alongside a switch back to another mode. The staged clear + keeps the row in view after that switch. + */} + {showsAdvanced("s3.public_token_secret") && ( + secrets.keepSaved("s3.public_token_secret")} + onClear={() => secrets.clearSaved("s3.public_token_secret")} + cleared={form.isClearStaged("s3.public_token_secret")} + onChange={(v) => secrets.setSecret("s3.public_token_secret", v)} + hint={t("web.admin.settings.storage.s3.tokenSecretHint")} + disabled={secrets.disabled} + restartRequired={restartKeys.has("s3.public_token_secret")} + managedByEnv={form.envVar("s3.public_token_secret")} + /> + )} + {showsAdvanced("s3.public_token_param") && ( + form.setValue("s3.public_token_param", v)} + restartRequired={restartKeys.has("s3.public_token_param")} + managedByEnv={form.envVar("s3.public_token_param")} + /> + )} + {showsAdvanced("s3.public_token_ttl") && ( + form.setValue("s3.public_token_ttl", v)} + restartRequired={restartKeys.has("s3.public_token_ttl")} + managedByEnv={form.envVar("s3.public_token_ttl")} + /> )} )} diff --git a/web/src/pages/setup-wizard/steps/ConnectStep.tsx b/web/src/pages/setup-wizard/steps/ConnectStep.tsx index c99a42cbef..68c4d267cf 100644 --- a/web/src/pages/setup-wizard/steps/ConnectStep.tsx +++ b/web/src/pages/setup-wizard/steps/ConnectStep.tsx @@ -21,6 +21,9 @@ export function ConnectStep() { // The snapshot always carries the effective value, so the default (on) is // never read as blank. const jellyfinEnabled = form.getValue("jellyfin_compat.enabled") === "true"; + // An address typed before turning Jellyfin off stays in view, marked as + // changed, so Continue never saves a value the admin can't see. + const addressKept = !jellyfinEnabled && form.isDirty("jellyfin_compat.public_url"); useStepSummary( "connect", jellyfinEnabled @@ -51,11 +54,10 @@ export function ConnectStep() { onChange={(v) => form.setValue("jellyfin_compat.enabled", v)} managedByEnv={form.envVar("jellyfin_compat.enabled")} /> - {/* An address typed before turning Jellyfin off stays in view, so - Continue never saves a value the admin can't see. */} - {jellyfinEnabled || form.isDirty("jellyfin_compat.public_url") ? ( + {jellyfinEnabled || addressKept ? ( `s3.${prefix}_${name}`; const urlAuth = form.getValue(key("url_auth")) || "presigned"; - // Link-mode settings show for the modes that use them, and while they hold - // an unsaved edit, so Continue never saves a value the admin can't see. - const showReadEndpoint = urlAuth !== "presigned" || form.isDirty("s3.public_read_endpoint"); - const showTokenSettings = - urlAuth === "cloudflare_token" || PUBLIC_S3_TOKEN_KEYS.some(form.isDirty); + // Link-mode settings show for the modes that use them. One the selected mode + // doesn't use stays, marked as changed, while it holds an unsaved edit, so + // Continue never saves a value the admin can't see. + const linkModeUses = (linkKey: string) => + linkKey === "s3.public_read_endpoint" + ? urlAuth !== "presigned" + : urlAuth === "cloudflare_token"; + const keptForEdit = (linkKey: string) => !linkModeUses(linkKey) && form.isDirty(linkKey); + const showsLinkSetting = (linkKey: string) => linkModeUses(linkKey) || form.isDirty(linkKey); return ( <> - {showReadEndpoint ? ( + {showsLinkSetting("s3.public_read_endpoint") ? ( ) : null} - {showTokenSettings ? ( - <> - form.setValue("s3.public_token_secret", v)} - sensitiveConfigured={form.sensitiveConfigured.includes("s3.public_token_secret")} - managedByEnv={form.envVar("s3.public_token_secret")} - /> - form.setValue("s3.public_token_param", v)} - managedByEnv={form.envVar("s3.public_token_param")} - /> - form.setValue("s3.public_token_ttl", v)} - managedByEnv={form.envVar("s3.public_token_ttl")} - /> - + {showsLinkSetting("s3.public_token_secret") ? ( + form.setValue("s3.public_token_secret", v)} + sensitiveConfigured={form.sensitiveConfigured.includes("s3.public_token_secret")} + managedByEnv={form.envVar("s3.public_token_secret")} + /> + ) : null} + {showsLinkSetting("s3.public_token_param") ? ( + form.setValue("s3.public_token_param", v)} + managedByEnv={form.envVar("s3.public_token_param")} + /> + ) : null} + {showsLinkSetting("s3.public_token_ttl") ? ( + form.setValue("s3.public_token_ttl", v)} + managedByEnv={form.envVar("s3.public_token_ttl")} + /> ) : null} ) : null} From d93afbda66dc5ce5d674913a8b4f34778d14d5c4 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 18:29:44 -0500 Subject: [PATCH 03/11] fix(web): drop the Jellyfin Web switch-off when its API draft goes With #4673, a draft for a key the environment takes over is dropped. When SILO_JELLYFIN_ENABLED takes over a staged API switch-off, the Jellyfin Web switch-off staged with it stayed, with no field to show it, and Save wrote it. The page now drops that switch-off whenever the API switch-off it goes with is no longer staged. The Redis takeover test now keeps a staged database number, the case in which the old switch state outlived #4673's draft drop. Co-Authored-By: Claude Opus 5.5 --- .../CompatibilityProxiesSettings.test.tsx | 52 +++++++++++++++++++ .../CompatibilityProxiesSettings.tsx | 12 ++++- .../pages/admin-settings/RedisGroup.test.tsx | 2 + 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx diff --git a/web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx b/web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx new file mode 100644 index 0000000000..41bcd3981d --- /dev/null +++ b/web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx @@ -0,0 +1,52 @@ +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { expect, it, vi } from "vitest"; + +import CompatibilityProxiesSettings from "./CompatibilityProxiesSettings"; + +const SETTINGS = { + "jellyfin_compat.enabled": "true", + "jellyfin_compat.web_enabled": "true", + "jellyfin_compat.public_url": "https://media.example.com", +}; + +const { sensitiveStatus } = vi.hoisted(() => ({ + sensitiveStatus: { + current: { configured: [], managed_by_env: [] } as { + configured: string[]; + managed_by_env: string[]; + managed_by_env_vars?: Record; + }, + }, +})); + +vi.mock("@/hooks/queries/admin/settings", () => ({ + useAdminServerSettings: () => ({ data: SETTINGS, isLoading: false }), + useAdminSensitiveStatus: () => ({ data: sensitiveStatus.current, isError: false }), + useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), + useJellyfinCompatStatus: () => ({ + data: { enabled: true, web_enabled: true, api_state: "running", web_state: "missing" }, + isLoading: false, + }), + useInstallJellyfinCompatWeb: () => ({ mutate: vi.fn(), isPending: false }), + useRemoveJellyfinCompatWeb: () => ({ mutate: vi.fn(), isPending: false }), + useUpdateJellyfinCompatSettings: () => ({ mutate: vi.fn(), isPending: false }), +})); + +vi.mock("@/hooks/useRestartKeys", () => ({ useRestartKeys: () => ({ has: () => false }) })); + +it("takes back the Jellyfin Web switch-off once the environment sets the API switch", async () => { + const { rerender } = render(); + await userEvent.click(screen.getByRole("switch", { name: "Allow Jellyfin apps to connect" })); + expect(screen.getByText("2 unsaved changes")).toBeInTheDocument(); + + // A restart with SILO_JELLYFIN_ENABLED set: the form drops the API draft. + sensitiveStatus.current = { + configured: [], + managed_by_env: ["jellyfin_compat.enabled"], + managed_by_env_vars: { "jellyfin_compat.enabled": "SILO_JELLYFIN_ENABLED" }, + }; + rerender(); + + expect(screen.queryByText(/unsaved change/)).not.toBeInTheDocument(); +}); diff --git a/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx b/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx index de3eeaf7d3..aeb58bb40c 100644 --- a/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx +++ b/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx @@ -1,4 +1,4 @@ -import { useMemo } from "react"; +import { useEffect, useMemo } from "react"; import { AlertCircle, CheckCircle2, @@ -179,6 +179,16 @@ export default function CompatibilityProxiesSettings() { const removeWeb = useRemoveJellyfinCompatWeb(); const updateCompatSettings = useUpdateJellyfinCompatSettings(); const status = statusQuery.data; + // The Jellyfin Web switch-off staged with an API switch-off (see + // setJellyfinAPIEnabled) has no field here, so it goes when that draft goes + // some other way, as when the environment takes the API switch over and the + // form drops its draft. + const webOffAlone = + form.isDirty("jellyfin_compat.web_enabled") && !form.isDirty("jellyfin_compat.enabled"); + const { resetValue } = form; + useEffect(() => { + if (webOffAlone) resetValue("jellyfin_compat.web_enabled"); + }, [webOffAlone, resetValue]); if (form.isLoading || statusQuery.isLoading) return ( diff --git a/web/src/pages/admin-settings/RedisGroup.test.tsx b/web/src/pages/admin-settings/RedisGroup.test.tsx index 6392411aed..db44a288ec 100644 --- a/web/src/pages/admin-settings/RedisGroup.test.tsx +++ b/web/src/pages/admin-settings/RedisGroup.test.tsx @@ -60,6 +60,8 @@ describe("RedisGroup", () => { it("shows the connection REDIS_URL sets once it takes over a staged switch-off", async () => { sensitiveStatus.current = { configured: ["redis.url"], managed_by_env: [] }; const { rerender } = render(); + // The number stays staged after the environment takes the URL over. + await userEvent.type(screen.getByLabelText("Database number"), "2"); await userEvent.click(screen.getByRole("switch", { name: "Use Redis" })); expect(screen.queryByLabelText("Connection URL")).not.toBeInTheDocument(); From f4ff246e0164afe5e4918948cb92c24070c9a2d5 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 18:44:14 -0500 Subject: [PATCH 04/11] fix(web): one rule for the Jellyfin Web switch-off; keep saved device order Review follow-ups on #4696: - Compatibility: the switch handler is back to staging Jellyfin Web off with every API switch-off, and one layout effect drops that draft whenever an API switch-off isn't staged. That covers flipping back, switching off an API already saved off, the window right after a save, and the environment taking the switch over. - Playback: a device toggle orders the list saved paths first, so turning a device off and back on restores the saved list even when detection lists the devices in another order. Co-Authored-By: Claude Opus 5.5 --- .../CompatibilityProxiesSettings.test.tsx | 15 +++++++++- .../CompatibilityProxiesSettings.tsx | 28 +++++++++---------- .../pages/admin-settings/PlaybackSettings.tsx | 18 ++++++------ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx b/web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx index 41bcd3981d..2fc9502329 100644 --- a/web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx +++ b/web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { expect, it, vi } from "vitest"; +import { beforeEach, expect, it, vi } from "vitest"; import CompatibilityProxiesSettings from "./CompatibilityProxiesSettings"; @@ -35,6 +35,19 @@ vi.mock("@/hooks/queries/admin/settings", () => ({ vi.mock("@/hooks/useRestartKeys", () => ({ useRestartKeys: () => ({ has: () => false }) })); +beforeEach(() => { + sensitiveStatus.current = { configured: [], managed_by_env: [] }; +}); + +it("stages nothing when the Jellyfin API is switched off and back on", async () => { + render(); + const api = screen.getByRole("switch", { name: "Allow Jellyfin apps to connect" }); + await userEvent.click(api); + await userEvent.click(api); + + expect(screen.queryByText(/unsaved change/)).not.toBeInTheDocument(); +}); + it("takes back the Jellyfin Web switch-off once the environment sets the API switch", async () => { const { rerender } = render(); await userEvent.click(screen.getByRole("switch", { name: "Allow Jellyfin apps to connect" })); diff --git a/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx b/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx index aeb58bb40c..9be90f1cde 100644 --- a/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx +++ b/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo } from "react"; +import { useLayoutEffect, useMemo } from "react"; import { AlertCircle, CheckCircle2, @@ -179,14 +179,20 @@ export default function CompatibilityProxiesSettings() { const removeWeb = useRemoveJellyfinCompatWeb(); const updateCompatSettings = useUpdateJellyfinCompatSettings(); const status = statusQuery.data; - // The Jellyfin Web switch-off staged with an API switch-off (see - // setJellyfinAPIEnabled) has no field here, so it goes when that draft goes - // some other way, as when the environment takes the API switch over and the - // form drops its draft. + // Switching the API off also turns Jellyfin Web off (setJellyfinAPIEnabled), + // as the server's own Jellyfin settings endpoint does. That edit has no field + // here, so it stays only while an API switch-off is staged: flipping the + // switch back, switching off an API that is already off, or the environment + // taking the switch over (the form then drops its draft) takes it back. + // A layout effect, so the save bar never paints the extra count. const webOffAlone = - form.isDirty("jellyfin_compat.web_enabled") && !form.isDirty("jellyfin_compat.enabled"); + form.isDirty("jellyfin_compat.web_enabled") && + !( + form.isDirty("jellyfin_compat.enabled") && + form.getValue("jellyfin_compat.enabled") === "false" + ); const { resetValue } = form; - useEffect(() => { + useLayoutEffect(() => { if (webOffAlone) resetValue("jellyfin_compat.web_enabled"); }, [webOffAlone, resetValue]); @@ -231,16 +237,10 @@ export default function CompatibilityProxiesSettings() { const publicURL = form.getValue("jellyfin_compat.public_url"); const serverID = form.getValue("jellyfin_compat.server_id"); - // Switching the API off also turns Jellyfin Web off, as the server's own - // Jellyfin settings endpoint does. That edit has no field on this page, so - // it is staged only with a switch-off that is itself a change, and any - // other flip takes it back rather than leave a change the admin can't see. const setJellyfinAPIEnabled = (value: string) => { form.setValue("jellyfin_compat.enabled", value); - if (value === "false" && form.getPersistedValue("jellyfin_compat.enabled") !== "false") { + if (value === "false") { form.setValue("jellyfin_compat.web_enabled", "false"); - } else { - form.resetValue("jellyfin_compat.web_enabled"); } }; const installJellyfinWeb = () => { diff --git a/web/src/pages/admin-settings/PlaybackSettings.tsx b/web/src/pages/admin-settings/PlaybackSettings.tsx index 74328b3cef..c83cb6a3a0 100644 --- a/web/src/pages/admin-settings/PlaybackSettings.tsx +++ b/web/src/pages/admin-settings/PlaybackSettings.tsx @@ -78,14 +78,16 @@ export default function PlaybackSettings() { const hwDevice = form.getValue("playback.hw_device"); const hwDeviceEnv = form.envVar("playback.hw_device"); const selectedDevices = parseHWDeviceList(hwDevice); - // Saved paths keep their rows, in their saved order, when the draft drops - // them, so switching off a device that detection doesn't list leaves its row - // in place, and switching it back on restores the saved list. - const deviceRows = buildHWDeviceRows( - hwDetection.data, - `${form.getPersistedValue("playback.hw_device")},${hwDevice}`, - ); - const deviceOrder = deviceRows.map((row) => row.path); + // Saved paths keep their rows when the draft drops them, so switching off a + // device that detection doesn't list leaves its row in place. A toggle orders + // the list saved paths first, in their saved order, so switching a device + // back on restores the saved list. + const savedDevices = parseHWDeviceList(form.getPersistedValue("playback.hw_device")); + const deviceRows = buildHWDeviceRows(hwDetection.data, [...savedDevices, hwDevice].join(",")); + const deviceOrder = [ + ...savedDevices, + ...deviceRows.map((row) => row.path).filter((path) => !savedDevices.includes(path)), + ]; // Balancing is QSV/VAAPI-only: NVENC addresses GPUs by CUDA index/UUID, so // the multi-select picker is hidden for it (the server uses the first // configured entry). From 844b85fda1a56dd1ca08433e08289b1bd0967821 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 18:51:44 -0500 Subject: [PATCH 05/11] fix(web): keep a kept device picker from adding NVENC-incompatible paths Review follow-ups on #4696: - Playback: shown under NVENC or "none" only because it holds an unsaved change, the device picker now only takes devices back to their saved state. NVENC reads the setting as a CUDA device, so adding render paths there would save a value NVENC can't use. - The Redis takeover test uses the server's shape (REDIS_URL manages both Redis keys) and keeps an unrelated edit staged, the case where the old switch state outlived the dropped drafts. Co-Authored-By: Claude Opus 5.5 --- .../pages/admin-settings/PlaybackSettings.tsx | 13 +++++++++---- .../pages/admin-settings/RedisGroup.test.tsx | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/web/src/pages/admin-settings/PlaybackSettings.tsx b/web/src/pages/admin-settings/PlaybackSettings.tsx index c83cb6a3a0..415a3ba1d2 100644 --- a/web/src/pages/admin-settings/PlaybackSettings.tsx +++ b/web/src/pages/admin-settings/PlaybackSettings.tsx @@ -95,10 +95,15 @@ export default function PlaybackSettings() { hwAccel === "nvenc" || (hwAccel === "auto" && hwDetection.data?.resolved === "nvenc"); const inventoriesDiverge = nodeInventoriesDiverge(hwDetection.data); // A device choice staged before switching acceleration keeps the picker in - // view, so Save never writes a value the admin can't see. + // view, so Save never writes a value the admin can't see. Under a mode the + // picker doesn't apply to, it only takes devices back to their saved state: + // NVENC reads the setting as a CUDA device, not a render path. + const devicePickerApplies = hwAccel !== "none" && !isNvenc; const showDevicePicker = - deviceRows.length > 0 && - ((hwAccel !== "none" && !isNvenc) || form.isDirty("playback.hw_device")); + deviceRows.length > 0 && (devicePickerApplies || form.isDirty("playback.hw_device")); + const deviceSwitchLocked = (path: string) => + hwDeviceEnv != null || + (!devicePickerApplies && selectedDevices.includes(path) === savedDevices.includes(path)); const nodes = useAdminNodes(); const trickplayExecution = @@ -431,7 +436,7 @@ export default function PlaybackSettings() { form.setValue( "playback.hw_device", diff --git a/web/src/pages/admin-settings/RedisGroup.test.tsx b/web/src/pages/admin-settings/RedisGroup.test.tsx index db44a288ec..e20563ab40 100644 --- a/web/src/pages/admin-settings/RedisGroup.test.tsx +++ b/web/src/pages/admin-settings/RedisGroup.test.tsx @@ -26,8 +26,10 @@ vi.mock("@/hooks/queries/admin/settings", () => ({ useCheckAdminSettingsConnection: () => ({ mutateAsync: vi.fn(), isPending: false }), })); +const OTHER_KEY = "server.public_url"; + function Harness() { - const form = useSettingsForm({ keys: REDIS_KEYS }); + const form = useSettingsForm({ keys: [...REDIS_KEYS, OTHER_KEY] }); return ( <> false }} secrets={{ keepSaved: form.resetValue, setSecret: form.setValue, disabled: false }} /> + {/* Another setting on the same page, so an edit can stay staged. */} + form.setValue(OTHER_KEY, e.target.value)} + />

{`${form.dirtyCount} staged`}

); @@ -60,15 +67,17 @@ describe("RedisGroup", () => { it("shows the connection REDIS_URL sets once it takes over a staged switch-off", async () => { sensitiveStatus.current = { configured: ["redis.url"], managed_by_env: [] }; const { rerender } = render(); - // The number stays staged after the environment takes the URL over. - await userEvent.type(screen.getByLabelText("Database number"), "2"); + // An edit elsewhere on the page stays staged after the environment takes + // the Redis keys over. + await userEvent.type(screen.getByLabelText("Other setting"), "https://media.example.com"); await userEvent.click(screen.getByRole("switch", { name: "Use Redis" })); expect(screen.queryByLabelText("Connection URL")).not.toBeInTheDocument(); + // REDIS_URL sets both keys, as the server reports it. sensitiveStatus.current = { configured: ["redis.url"], - managed_by_env: ["redis.url"], - managed_by_env_vars: { "redis.url": "REDIS_URL" }, + managed_by_env: ["redis.url", "redis.db"], + managed_by_env_vars: { "redis.url": "REDIS_URL", "redis.db": "REDIS_URL" }, }; rerender(); From 1b4f2bae54f3c23cf44a385da189411a54ab2206 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 18:57:24 -0500 Subject: [PATCH 06/11] fix(web): mark the changed devices in a kept device picker Review follow-up on #4696: under a mode the device picker doesn't apply to, a device row whose switch differs from the saved list now carries the unsaved-change dot, like every other row kept for an edit. Co-Authored-By: Claude Opus 5.5 --- web/src/pages/admin-settings/PlaybackSettings.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/src/pages/admin-settings/PlaybackSettings.tsx b/web/src/pages/admin-settings/PlaybackSettings.tsx index 415a3ba1d2..018fabfb67 100644 --- a/web/src/pages/admin-settings/PlaybackSettings.tsx +++ b/web/src/pages/admin-settings/PlaybackSettings.tsx @@ -101,9 +101,13 @@ export default function PlaybackSettings() { const devicePickerApplies = hwAccel !== "none" && !isNvenc; const showDevicePicker = deviceRows.length > 0 && (devicePickerApplies || form.isDirty("playback.hw_device")); + const deviceChanged = (path: string) => + selectedDevices.includes(path) !== savedDevices.includes(path); + // Kept under such a mode, a row marks a device whose switch differs from + // the saved list, and only those switches stay unlocked. + const deviceKeptForEdit = (path: string) => !devicePickerApplies && deviceChanged(path); const deviceSwitchLocked = (path: string) => - hwDeviceEnv != null || - (!devicePickerApplies && selectedDevices.includes(path) === savedDevices.includes(path)); + hwDeviceEnv != null || (!devicePickerApplies && !deviceChanged(path)); const nodes = useAdminNodes(); const trickplayExecution = @@ -413,6 +417,7 @@ export default function PlaybackSettings() { {deviceRows.map((row, index) => ( Date: Fri, 20 Nov 2026 19:20:40 -0500 Subject: [PATCH 07/11] fix(web): treat a device toggle back to the saved list as no change Review follow-up on #4696: a saved device list that isn't in canonical form (a space after a comma) never matched the toggled string, so switching back to the saved devices left a draft with every switch of a kept picker locked. A toggle that lands on the saved devices now drops the draft. Co-Authored-By: Claude Opus 5.5 --- .../pages/admin-settings/PlaybackSettings.tsx | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/web/src/pages/admin-settings/PlaybackSettings.tsx b/web/src/pages/admin-settings/PlaybackSettings.tsx index 018fabfb67..7ee821c2e9 100644 --- a/web/src/pages/admin-settings/PlaybackSettings.tsx +++ b/web/src/pages/admin-settings/PlaybackSettings.tsx @@ -442,16 +442,20 @@ export default function PlaybackSettings() { checked={selectedDevices.includes(row.path)} aria-label={row.description} disabled={deviceSwitchLocked(row.path)} - onCheckedChange={() => - form.setValue( - "playback.hw_device", - toggleHWDevice( - form.getValue("playback.hw_device"), - row.path, - deviceOrder, - ), - ) - } + onCheckedChange={() => { + const next = toggleHWDevice( + form.getValue("playback.hw_device"), + row.path, + deviceOrder, + ); + // Back to the saved devices, however the saved value + // is spaced, is no change. + if (next === savedDevices.join(",")) { + form.resetValue("playback.hw_device"); + } else { + form.setValue("playback.hw_device", next); + } + }} /> ))} From c5c64cd778a66138da8e9ddfe1ff6e1666b7d0ea Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:35:11 -0500 Subject: [PATCH 08/11] test(web): check that only the unrelated edit survives a Redis takeover Review follow-up on #4696. Co-Authored-By: Claude Opus 5.5 --- web/src/pages/admin-settings/RedisGroup.test.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/src/pages/admin-settings/RedisGroup.test.tsx b/web/src/pages/admin-settings/RedisGroup.test.tsx index e20563ab40..2a064c837e 100644 --- a/web/src/pages/admin-settings/RedisGroup.test.tsx +++ b/web/src/pages/admin-settings/RedisGroup.test.tsx @@ -83,5 +83,7 @@ describe("RedisGroup", () => { expect(screen.getByRole("switch", { name: "Use Redis" })).toBeChecked(); expect(screen.getByLabelText("Connection URL")).toBeInTheDocument(); + // The Redis drafts went with the takeover; the other edit stays. + expect(screen.getByText("1 staged")).toBeInTheDocument(); }); }); From 92bb206b8f7017b934d7042a0e1b821fe2017423 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:36:10 -0500 Subject: [PATCH 09/11] test(web): stage the Redis number with the switch-off in the takeover test Review follow-up on #4696: the fixture reports a saved database number, as the server does for a saved URL, so the switch-off stages both Redis keys and the test checks that only the unrelated edit survives REDIS_URL taking them over. Co-Authored-By: Claude Opus 5.5 --- web/src/pages/admin-settings/RedisGroup.test.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/src/pages/admin-settings/RedisGroup.test.tsx b/web/src/pages/admin-settings/RedisGroup.test.tsx index 2a064c837e..6795d4f6e6 100644 --- a/web/src/pages/admin-settings/RedisGroup.test.tsx +++ b/web/src/pages/admin-settings/RedisGroup.test.tsx @@ -20,7 +20,8 @@ const { sensitiveStatus } = vi.hoisted(() => ({ vi.mock("@/hooks/queries/admin/settings", () => ({ // The snapshot never carries the URL; whether one is saved comes from the // protected-credential status. - useAdminServerSettings: () => ({ data: { "redis.db": "" }, isLoading: false }), + // The server reports the number in use: 0 when the URL names none. + useAdminServerSettings: () => ({ data: { "redis.db": "0" }, isLoading: false }), useAdminSensitiveStatus: () => ({ data: sensitiveStatus.current, isError: false }), useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), useCheckAdminSettingsConnection: () => ({ mutateAsync: vi.fn(), isPending: false }), @@ -72,6 +73,8 @@ describe("RedisGroup", () => { await userEvent.type(screen.getByLabelText("Other setting"), "https://media.example.com"); await userEvent.click(screen.getByRole("switch", { name: "Use Redis" })); expect(screen.queryByLabelText("Connection URL")).not.toBeInTheDocument(); + // The switch-off stages the URL and the number with it. + expect(screen.getByText("3 staged")).toBeInTheDocument(); // REDIS_URL sets both keys, as the server reports it. sensitiveStatus.current = { From 9c49a5af6343a67333a229845ca053921bb69127 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:39:43 -0500 Subject: [PATCH 10/11] fix(web): keep a device revert staged while a save settles Review follow-up on #4696 (Kody): a device toggle back to the saved list reset the draft directly, so during a save of that setting the revert was dropped and the save wrote the unwanted devices. The toggle now stages the saved string itself and lets the form decide whether that undoes the edit, as it does for every other field; only an unset value, which the snapshot never carries, is dropped directly, and not while a save is in flight. Co-Authored-By: Claude Opus 5.5 --- web/src/pages/admin-settings/PlaybackSettings.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/src/pages/admin-settings/PlaybackSettings.tsx b/web/src/pages/admin-settings/PlaybackSettings.tsx index 7ee821c2e9..f85fbb96c0 100644 --- a/web/src/pages/admin-settings/PlaybackSettings.tsx +++ b/web/src/pages/admin-settings/PlaybackSettings.tsx @@ -448,12 +448,19 @@ export default function PlaybackSettings() { row.path, deviceOrder, ); - // Back to the saved devices, however the saved value - // is spaced, is no change. - if (next === savedDevices.join(",")) { + // Back to the saved devices stages the saved string + // itself, so the form can tell it undoes the edit + // however that string is spaced, and keeps it staged + // while a save settles. An unset value is never in + // the snapshot, so outside a save that draft is + // dropped directly. + const saved = form.getPersistedValue("playback.hw_device"); + if (next !== savedDevices.join(",")) { + form.setValue("playback.hw_device", next); + } else if (saved === "" && !form.isSaving) { form.resetValue("playback.hw_device"); } else { - form.setValue("playback.hw_device", next); + form.setValue("playback.hw_device", saved); } }} /> From 6ea774bf51add17d4130fb341cf1d42fdac8bd32 Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:45:28 -0500 Subject: [PATCH 11/11] fix(web): let a kept device picker always reach the saved list Review follow-up on #4696 (Sol S7): after a settings refresh, a staged device list could match the saved devices or differ only in order, and the kept picker under NVENC or Software then locked every switch. Under a mode the picker doesn't apply to, any device can now be switched off and only saved devices switched on, so the saved list is always reachable and no render path can be added for NVENC. A list that differs only in order marks its selected rows. Component tests cover NVENC refusing a new render path and an order-only list going back to the saved one; both fail on main. Co-Authored-By: Claude Opus 5.5 --- .../admin-settings/PlaybackSettings.test.tsx | 107 ++++++++++++++++++ .../pages/admin-settings/PlaybackSettings.tsx | 21 ++-- 2 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 web/src/pages/admin-settings/PlaybackSettings.test.tsx diff --git a/web/src/pages/admin-settings/PlaybackSettings.test.tsx b/web/src/pages/admin-settings/PlaybackSettings.test.tsx new file mode 100644 index 0000000000..bcb7a35b5a --- /dev/null +++ b/web/src/pages/admin-settings/PlaybackSettings.test.tsx @@ -0,0 +1,107 @@ +import { render, screen, within } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { MemoryRouter } from "react-router"; +import { beforeEach, describe, expect, it, vi } from "vitest"; + +import PlaybackSettings from "./PlaybackSettings"; + +window.HTMLElement.prototype.hasPointerCapture ??= () => false; +window.HTMLElement.prototype.setPointerCapture ??= () => {}; +window.HTMLElement.prototype.releasePointerCapture ??= () => {}; +window.HTMLElement.prototype.scrollIntoView ??= () => {}; + +const A = "/dev/dri/renderD128"; +const B = "/dev/dri/renderD129"; +const C = "/dev/dri/renderD130"; + +const { settings } = vi.hoisted(() => ({ + settings: { current: {} as Record }, +})); + +vi.mock("@/hooks/queries/admin/settings", () => ({ + useAdminServerSettings: () => ({ data: settings.current, isLoading: false }), + useAdminSensitiveStatus: () => ({ data: { configured: [], managed_by_env: [] }, isError: false }), + useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), +})); +vi.mock("@/hooks/queries/admin/system", () => ({ + useHWAccelDetection: () => ({ + data: { + resolved: "vaapi", + render_device_details: [ + { path: A, description: "GPU A" }, + { path: B, description: "GPU B" }, + { path: C, description: "GPU C" }, + ], + }, + isLoading: false, + }), +})); +vi.mock("@/hooks/queries/admin/nodes", () => ({ + useAdminNodes: () => ({ data: [], isSuccess: true }), +})); +vi.mock("@/hooks/queries/admin/libraries", () => ({ + useLibraryCapabilities: () => ({ data: { trickplay: false } }), +})); +vi.mock("@/hooks/queries/admin/markers", () => ({ + useAdminMarkerCapabilities: () => ({ data: undefined }), +})); +vi.mock("@/hooks/queries/admin/trickplay", () => ({ + useAdminTrickplayLibraries: () => ({ data: [], isSuccess: true }), +})); +vi.mock("@/hooks/useRestartKeys", () => ({ useRestartKeys: () => ({ has: () => false }) })); +vi.mock("./MarkerTasksCard", () => ({ MarkerTasksCard: () => null })); + +const page = ( + + + +); + +async function openDevices() { + const transcoding = within(screen.getByRole("group", { name: "Transcoding" })); + await userEvent.click(transcoding.getByRole("button", { name: /Advanced/ })); +} + +async function switchToNvenc() { + await userEvent.click(screen.getByRole("combobox", { name: "Hardware acceleration" })); + await userEvent.click(screen.getByRole("option", { name: "NVIDIA NVENC" })); +} + +describe("hardware device picker kept for an unsaved change", () => { + beforeEach(() => { + // Disclosures remember being opened; start every case collapsed. + localStorage.clear(); + settings.current = { "playback.hw_accel": "vaapi", "playback.hw_device": A }; + }); + + it("under NVENC only takes the staged device back off", async () => { + render(page); + await openDevices(); + await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); + await switchToNvenc(); + + // A render path NVENC can't use can't be added, and the staged one can + // go back off. + expect(screen.getByRole("switch", { name: "GPU C" })).toBeDisabled(); + await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); + + expect(screen.queryByRole("switch", { name: "GPU B" })).not.toBeInTheDocument(); + expect(screen.getByText("1 unsaved change")).toBeInTheDocument(); + }); + + it("can restore a saved list that differs from the staged one only in order", async () => { + const { rerender } = render(page); + await openDevices(); + await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); + // Someone else saves the same devices in the other order. + settings.current = { "playback.hw_accel": "vaapi", "playback.hw_device": `${B},${A}` }; + rerender(page); + await switchToNvenc(); + + await userEvent.click(screen.getByRole("switch", { name: "GPU A" })); + await userEvent.click(screen.getByRole("switch", { name: "GPU A" })); + + expect(screen.queryByRole("switch", { name: "GPU A" })).not.toBeInTheDocument(); + expect(screen.getByText("1 unsaved change")).toBeInTheDocument(); + }); +}); diff --git a/web/src/pages/admin-settings/PlaybackSettings.tsx b/web/src/pages/admin-settings/PlaybackSettings.tsx index f85fbb96c0..5701f803b6 100644 --- a/web/src/pages/admin-settings/PlaybackSettings.tsx +++ b/web/src/pages/admin-settings/PlaybackSettings.tsx @@ -96,18 +96,23 @@ export default function PlaybackSettings() { const inventoriesDiverge = nodeInventoriesDiverge(hwDetection.data); // A device choice staged before switching acceleration keeps the picker in // view, so Save never writes a value the admin can't see. Under a mode the - // picker doesn't apply to, it only takes devices back to their saved state: - // NVENC reads the setting as a CUDA device, not a render path. + // picker doesn't apply to, it only takes the list back toward the saved one: + // any device can be switched off, and only saved devices on. NVENC reads the + // setting as a CUDA device, so render paths can't be added there. const devicePickerApplies = hwAccel !== "none" && !isNvenc; - const showDevicePicker = - deviceRows.length > 0 && (devicePickerApplies || form.isDirty("playback.hw_device")); + const hwDeviceDirty = form.isDirty("playback.hw_device"); + const showDevicePicker = deviceRows.length > 0 && (devicePickerApplies || hwDeviceDirty); const deviceChanged = (path: string) => selectedDevices.includes(path) !== savedDevices.includes(path); - // Kept under such a mode, a row marks a device whose switch differs from - // the saved list, and only those switches stay unlocked. - const deviceKeptForEdit = (path: string) => !devicePickerApplies && deviceChanged(path); + // A staged list can match the saved devices and differ only in order, as + // after a refresh; its selected rows then carry the change. + const orderOnlyDraft = hwDeviceDirty && !deviceRows.some((row) => deviceChanged(row.path)); + const deviceKeptForEdit = (path: string) => + !devicePickerApplies && + (deviceChanged(path) || (orderOnlyDraft && selectedDevices.includes(path))); const deviceSwitchLocked = (path: string) => - hwDeviceEnv != null || (!devicePickerApplies && !deviceChanged(path)); + hwDeviceEnv != null || + (!devicePickerApplies && !selectedDevices.includes(path) && !savedDevices.includes(path)); const nodes = useAdminNodes(); const trickplayExecution =