From 54a79620434eab7eb388e8f76dbf9c48bc6f647a Mon Sep 17 00:00:00 2001 From: Vadim Lazuk Date: Wed, 25 Nov 2026 18:03:43 +0300 Subject: [PATCH] fix(settings): keep an uncommitted Run Targets field edit off the next target (#5900) The run target list switches selection on mousedown, before the Published ports / Compose files field's blur commits its draft, so the commit closure already saw the newly selected target and wrote the edit onto it. The Target Settings form is now keyed by target id, so switching targets remounts it and drops the uncommitted draft. Fixes #5872 Co-authored-by: Inf1mum <8135225+Inf1mum@users.noreply.github.com> --- .../__tests__/runTargetsSwitchDraft.test.tsx | 59 +++++++++++++++++++ .../settings/pages/RunTargetsBody.tsx | 4 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx diff --git a/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx b/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx new file mode 100644 index 0000000000..7dd05b203b --- /dev/null +++ b/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx @@ -0,0 +1,59 @@ +import { cleanup, fireEvent, render, screen } from "@testing-library/react"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +vi.mock("@/platform/ipc", async (importOriginal) => { + const real = await importOriginal(); + return { ...real, isTauri: () => false }; +}); + +const { PageContext } = await import("../components/context"); +const { RunTargetsEditor } = await import("../pages/RunTargetsBody"); +const { useSettingsDialog } = await import("../model/staging"); +const { DEFAULT_SETTINGS } = await import("../model/schema"); +const { DEFAULT_RUN_TARGET } = await import("@/platform/remoteSettings"); + +const TARGETS = [ + { ...DEFAULT_RUN_TARGET, kind: "compose" as const, id: "odoo110", name: "odoo110", ports: ["8069:8069"] }, + { ...DEFAULT_RUN_TARGET, kind: "compose" as const, id: "odoo170", name: "odoo170", ports: ["9000:9000"] }, +]; + +function mount() { + const settings = structuredClone(DEFAULT_SETTINGS) as typeof DEFAULT_SETTINGS & Record; + settings.runTargets = TARGETS; + useSettingsDialog.setState({ + base: structuredClone(settings), + globalBase: settings, + staged: {}, + query: "", + }); + render( + + + , + ); +} + +const portsBox = () => screen.getByRole("textbox", { name: "Published ports" }) as HTMLInputElement; + +beforeEach(() => { + Object.assign(window, { __TAURI_INTERNALS__: { transformCallback: () => 1 } }); +}); +afterEach(() => { + cleanup(); +}); + +describe("Run Targets detail form", () => { + it("does not commit an uncommitted ports edit to the target selected while it is open", () => { + mount(); + // An edit to odoo110's published ports that ListField has not committed yet. + fireEvent.change(portsBox(), { target: { value: "8069" } }); + // Selecting another target switches selection on mousedown, before the blur commits. + fireEvent.mouseDown(screen.getByRole("option", { name: /odoo170/ })); + fireEvent.blur(portsBox()); + // odoo170 keeps its own ports; the uncommitted draft is not written over them. + expect(portsBox().value).toBe("9000:9000"); + // And odoo110 still holds what it held before the edit was committed anywhere. + fireEvent.mouseDown(screen.getByRole("option", { name: /odoo110/ })); + expect(portsBox().value).toBe("8069:8069"); + }); +}); diff --git a/src/features/settings/pages/RunTargetsBody.tsx b/src/features/settings/pages/RunTargetsBody.tsx index 3a1033c863..adaa55d35d 100644 --- a/src/features/settings/pages/RunTargetsBody.tsx +++ b/src/features/settings/pages/RunTargetsBody.tsx @@ -516,7 +516,9 @@ export function RunTargetsEditor() { {current && ( -
+ // Keyed by target id: switching targets remounts the form and drops any + // uncommitted ListField draft instead of committing it to the new target. +
update({ name })} />