Skip to content

Commit 91178a7

Browse files
only21milclaude
andcommitted
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 <[email protected]>
1 parent 02ce487 commit 91178a7

2 files changed

Lines changed: 40 additions & 18 deletions

File tree

‎apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx‎

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "vite-plus/test";
1+
import { describe, expect, it, vi } from "vite-plus/test";
22
import { page, userEvent } from "vite-plus/test/browser";
33

44
import { render } from "../../../test/render";
@@ -23,21 +23,23 @@ const themeFile = (name: string, accent?: string) =>
2323
new File([JSON.stringify(theme(name, accent))], `${name}.json`, { type: "application/json" });
2424

2525
describe("ThemeImportDialog", () => {
26-
it("lets the user update an installed theme when another file in the batch fails", async () => {
27-
using _themes = {
28-
[Symbol.dispose]: () => {
29-
window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY);
30-
invalidateCustomThemes();
31-
},
32-
};
26+
const uploadBatchWithConflictAndFailure = async () => {
27+
await using stack = new AsyncDisposableStack();
28+
stack.defer(() => {
29+
window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY);
30+
invalidateCustomThemes();
31+
});
3332
installCustomTheme(parseThemeFile(theme("Dusk")));
34-
await using _screen = await render(
35-
<ThemeImportDialog
36-
open
37-
onOpenChange={() => {}}
38-
onImported={() => true}
39-
onImportedMany={() => {}}
40-
/>,
33+
const onOpenChange = vi.fn();
34+
stack.use(
35+
await render(
36+
<ThemeImportDialog
37+
open
38+
onOpenChange={onOpenChange}
39+
onImported={() => true}
40+
onImportedMany={() => {}}
41+
/>,
42+
),
4143
);
4244

4345
const input = document.querySelector<HTMLInputElement>('input[type="file"]')!;
@@ -49,12 +51,31 @@ describe("ThemeImportDialog", () => {
4951

5052
await expect.element(page.getByText("Already installed")).toBeVisible();
5153
await expect.element(page.getByText(/^broken\.json:/)).toBeVisible();
54+
return { onOpenChange, cleanup: stack.move() };
55+
};
56+
57+
it("lets the user update an installed theme when another file in the batch fails", async () => {
58+
const { onOpenChange, cleanup } = await uploadBatchWithConflictAndFailure();
59+
await using _cleanup = cleanup;
5260
expect(getCustomThemes().map((theme) => theme.label)).toContain("Dawn");
5361

5462
await page.getByRole("button", { name: "Update existing" }).click();
5563
invalidateCustomThemes();
5664
expect(getCustomThemes().find((theme) => theme.label === "Dusk")?.colors).toEqual(
5765
parseThemeFile(theme("Dusk", "#f97316")).colors,
5866
);
67+
await expect.element(page.getByText(/^broken\.json:/)).toBeVisible();
68+
expect(onOpenChange).not.toHaveBeenCalledWith(false);
69+
});
70+
71+
it("keeps a batch file failure visible after keeping both copies", async () => {
72+
const { onOpenChange, cleanup } = await uploadBatchWithConflictAndFailure();
73+
await using _cleanup = cleanup;
74+
75+
await page.getByRole("button", { name: "Keep both" }).click();
76+
invalidateCustomThemes();
77+
expect(getCustomThemes().map((theme) => theme.label)).toContain("Dusk (1)");
78+
await expect.element(page.getByText(/^broken\.json:/)).toBeVisible();
79+
expect(onOpenChange).not.toHaveBeenCalledWith(false);
5980
});
6081
});

‎apps/web/src/components/settings/ThemeImportDialog.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export function ThemeImportDialog({
249249
}
250250
}
251251
if (installed.length > 0) onImportedMany(installed, { updated: false });
252-
if (failures.length > 0) setError(failures.join("; "));
252+
setError(failures.length > 0 ? failures.join("; ") : null);
253253
if (conflicting.length > 0) {
254254
setConflicts(conflicting);
255255
} else if (installed.length > 0 && failures.length === 0) {
@@ -351,8 +351,9 @@ export function ThemeImportDialog({
351351
}
352352
if (resolved.length > 0) onImportedMany(resolved, { updated: mode === "update" });
353353
setConflicts(null);
354-
if (failures.length > 0) setError(failures.join("; "));
355-
else onOpenChange(false);
354+
// `error` still holds this batch's file failures; resolving conflicts must not hide them.
355+
if (failures.length > 0) setError([error, ...failures].filter(Boolean).join("; "));
356+
else if (!error) onOpenChange(false);
356357
};
357358

358359
const handleSubmit = () => {

0 commit comments

Comments
 (0)