From a74039121cada94aa67e9aabf5d70aeded47981a Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Tue, 20 Oct 2026 20:50:06 -0500 Subject: [PATCH 1/3] fix(web): show theme conflicts even when another import fails When a multi-file theme import had both a failed file and a file that matched an installed theme, the dialog showed only the error. The duplicate was neither installed nor offered for Update existing or Keep both. Show the conflict prompt whenever there are conflicts, next to the error, and close the dialog only when nothing failed. Co-Authored-By: Claude Opus 5.5 --- .../ThemeImportDialog.browser.test.tsx | 53 +++++++++++++++++++ .../components/settings/ThemeImportDialog.tsx | 7 ++- 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx diff --git a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx new file mode 100644 index 000000000000..451a8169e7b9 --- /dev/null +++ b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx @@ -0,0 +1,53 @@ +import { afterEach, describe, expect, it } from "vite-plus/test"; +import { page, userEvent } from "vite-plus/test/browser"; + +import { render } from "../../../test/render"; +import { + CUSTOM_THEMES_STORAGE_KEY, + getCustomThemes, + installCustomTheme, + invalidateCustomThemes, + parseThemeFile, + THEME_FILE_VERSION, +} from "../../themePalette"; +import { ThemeImportDialog } from "./ThemeImportDialog"; + +const theme = (name: string) => ({ + version: THEME_FILE_VERSION, + name, + appearance: "dark", + colors: { accent: "#3b82f6" }, +}); + +const themeFile = (name: string) => + new File([JSON.stringify(theme(name))], `${name}.json`, { type: "application/json" }); + +afterEach(() => { + window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY); + invalidateCustomThemes(); +}); + +describe("ThemeImportDialog", () => { + it("offers to resolve an installed theme when another file in the batch fails", async () => { + installCustomTheme(parseThemeFile(theme("Dusk"))); + await using _screen = await render( + {}} + onImported={() => true} + onImportedMany={() => {}} + />, + ); + + const input = document.querySelector('input[type="file"]')!; + await userEvent.upload(input, [ + themeFile("Dawn"), + themeFile("Dusk"), + new File(["{"], "broken.json", { type: "application/json" }), + ]); + + await expect.element(page.getByText("Already installed")).toBeVisible(); + await expect.element(page.getByRole("alert")).toHaveTextContent(/broken\.json/); + expect(getCustomThemes().map((theme) => theme.label)).toContain("Dawn"); + }); +}); diff --git a/apps/web/src/components/settings/ThemeImportDialog.tsx b/apps/web/src/components/settings/ThemeImportDialog.tsx index 74eabfc8a9cc..752019cf04bc 100644 --- a/apps/web/src/components/settings/ThemeImportDialog.tsx +++ b/apps/web/src/components/settings/ThemeImportDialog.tsx @@ -249,11 +249,10 @@ export function ThemeImportDialog({ } } if (installed.length > 0) onImportedMany(installed, { updated: false }); - if (failures.length > 0) { - setError(failures.join(" — ")); - } else if (conflicting.length > 0) { + if (failures.length > 0) setError(failures.join(" — ")); + if (conflicting.length > 0) { setConflicts(conflicting); - } else if (installed.length > 0) { + } else if (installed.length > 0 && failures.length === 0) { onOpenChange(false); } }; From 26743a0cd2d31b2baf097bcde5eab522ce4776c2 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Wed, 21 Oct 2026 08:53:49 -0500 Subject: [PATCH 2/3] test(web): resolve the conflict after a failed batch file Click Update existing after the failed batch and check the stored theme took the incoming colors. Clean up stored themes with a disposable instead of afterEach, as the browser-test lint rule asks. Co-Authored-By: Claude Opus 5.5 --- .../ThemeImportDialog.browser.test.tsx | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx index 451a8169e7b9..e337151d92ce 100644 --- a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx +++ b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, it } from "vite-plus/test"; +import { describe, expect, it } from "vite-plus/test"; import { page, userEvent } from "vite-plus/test/browser"; import { render } from "../../../test/render"; @@ -12,23 +12,24 @@ import { } from "../../themePalette"; import { ThemeImportDialog } from "./ThemeImportDialog"; -const theme = (name: string) => ({ +const theme = (name: string, accent = "#3b82f6") => ({ version: THEME_FILE_VERSION, name, appearance: "dark", - colors: { accent: "#3b82f6" }, + colors: { accent }, }); -const themeFile = (name: string) => - new File([JSON.stringify(theme(name))], `${name}.json`, { type: "application/json" }); - -afterEach(() => { - window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY); - invalidateCustomThemes(); -}); +const themeFile = (name: string, accent?: string) => + new File([JSON.stringify(theme(name, accent))], `${name}.json`, { type: "application/json" }); describe("ThemeImportDialog", () => { - it("offers to resolve an installed theme when another file in the batch fails", async () => { + it("lets the user update an installed theme when another file in the batch fails", async () => { + using _themes = { + [Symbol.dispose]: () => { + window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY); + invalidateCustomThemes(); + }, + }; installCustomTheme(parseThemeFile(theme("Dusk"))); await using _screen = await render( { const input = document.querySelector('input[type="file"]')!; await userEvent.upload(input, [ themeFile("Dawn"), - themeFile("Dusk"), + themeFile("Dusk", "#f97316"), new File(["{"], "broken.json", { type: "application/json" }), ]); await expect.element(page.getByText("Already installed")).toBeVisible(); - await expect.element(page.getByRole("alert")).toHaveTextContent(/broken\.json/); + await expect.element(page.getByText(/^broken\.json:/)).toBeVisible(); expect(getCustomThemes().map((theme) => theme.label)).toContain("Dawn"); + + await page.getByRole("button", { name: "Update existing" }).click(); + invalidateCustomThemes(); + expect(getCustomThemes().find((theme) => theme.label === "Dusk")?.colors).toEqual( + parseThemeFile(theme("Dusk", "#f97316")).colors, + ); }); }); From 91178a77dd2b5044f04eaa0efff453d5edd68bc7 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Fri, 23 Oct 2026 21:56:29 -0500 Subject: [PATCH 3/3] fix(web): keep theme import open after resolving conflicts in a failed batch Resolving conflicts closed the dialog even when another file in the batch failed, hiding that failure. The batch now resets the error to its own failures, and conflict resolution keeps the dialog open and appends to that error instead of replacing it. Co-Authored-By: Claude Opus 5.5 --- .../ThemeImportDialog.browser.test.tsx | 51 +++++++++++++------ .../components/settings/ThemeImportDialog.tsx | 7 +-- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx index e337151d92ce..4991da0d28f8 100644 --- a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx +++ b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx @@ -1,4 +1,4 @@ -import { describe, expect, it } from "vite-plus/test"; +import { describe, expect, it, vi } from "vite-plus/test"; import { page, userEvent } from "vite-plus/test/browser"; import { render } from "../../../test/render"; @@ -23,21 +23,23 @@ const themeFile = (name: string, accent?: string) => new File([JSON.stringify(theme(name, accent))], `${name}.json`, { type: "application/json" }); describe("ThemeImportDialog", () => { - it("lets the user update an installed theme when another file in the batch fails", async () => { - using _themes = { - [Symbol.dispose]: () => { - window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY); - invalidateCustomThemes(); - }, - }; + const uploadBatchWithConflictAndFailure = async () => { + await using stack = new AsyncDisposableStack(); + stack.defer(() => { + window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY); + invalidateCustomThemes(); + }); installCustomTheme(parseThemeFile(theme("Dusk"))); - await using _screen = await render( - {}} - onImported={() => true} - onImportedMany={() => {}} - />, + const onOpenChange = vi.fn(); + stack.use( + await render( + true} + onImportedMany={() => {}} + />, + ), ); const input = document.querySelector('input[type="file"]')!; @@ -49,6 +51,12 @@ describe("ThemeImportDialog", () => { await expect.element(page.getByText("Already installed")).toBeVisible(); await expect.element(page.getByText(/^broken\.json:/)).toBeVisible(); + return { onOpenChange, cleanup: stack.move() }; + }; + + it("lets the user update an installed theme when another file in the batch fails", async () => { + const { onOpenChange, cleanup } = await uploadBatchWithConflictAndFailure(); + await using _cleanup = cleanup; expect(getCustomThemes().map((theme) => theme.label)).toContain("Dawn"); await page.getByRole("button", { name: "Update existing" }).click(); @@ -56,5 +64,18 @@ describe("ThemeImportDialog", () => { expect(getCustomThemes().find((theme) => theme.label === "Dusk")?.colors).toEqual( parseThemeFile(theme("Dusk", "#f97316")).colors, ); + await expect.element(page.getByText(/^broken\.json:/)).toBeVisible(); + expect(onOpenChange).not.toHaveBeenCalledWith(false); + }); + + it("keeps a batch file failure visible after keeping both copies", async () => { + const { onOpenChange, cleanup } = await uploadBatchWithConflictAndFailure(); + await using _cleanup = cleanup; + + await page.getByRole("button", { name: "Keep both" }).click(); + invalidateCustomThemes(); + expect(getCustomThemes().map((theme) => theme.label)).toContain("Dusk (1)"); + await expect.element(page.getByText(/^broken\.json:/)).toBeVisible(); + expect(onOpenChange).not.toHaveBeenCalledWith(false); }); }); diff --git a/apps/web/src/components/settings/ThemeImportDialog.tsx b/apps/web/src/components/settings/ThemeImportDialog.tsx index 1ec44465350f..a1d9a9245073 100644 --- a/apps/web/src/components/settings/ThemeImportDialog.tsx +++ b/apps/web/src/components/settings/ThemeImportDialog.tsx @@ -249,7 +249,7 @@ export function ThemeImportDialog({ } } if (installed.length > 0) onImportedMany(installed, { updated: false }); - if (failures.length > 0) setError(failures.join("; ")); + setError(failures.length > 0 ? failures.join("; ") : null); if (conflicting.length > 0) { setConflicts(conflicting); } else if (installed.length > 0 && failures.length === 0) { @@ -351,8 +351,9 @@ export function ThemeImportDialog({ } if (resolved.length > 0) onImportedMany(resolved, { updated: mode === "update" }); setConflicts(null); - if (failures.length > 0) setError(failures.join("; ")); - else onOpenChange(false); + // `error` still holds this batch's file failures; resolving conflicts must not hide them. + if (failures.length > 0) setError([error, ...failures].filter(Boolean).join("; ")); + else if (!error) onOpenChange(false); }; const handleSubmit = () => {