Skip to content

Commit 80ae9b5

Browse files
only21milclaudemaria-rcks
authored
fix(web): show theme conflicts even when another import fails (pingdotgg#23223)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 781cc55 commit 80ae9b5

2 files changed

Lines changed: 63 additions & 6 deletions

File tree

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { describe, expect, it, vi } from "vite-plus/test";
33
import { page, userEvent } from "vite-plus/test/browser";
44

55
import { render } from "../../../test/render";
6+
import {
7+
CUSTOM_THEMES_STORAGE_KEY,
8+
getCustomThemes,
9+
installCustomTheme,
10+
invalidateCustomThemes,
11+
parseThemeFile,
12+
THEME_FILE_VERSION,
13+
} from "../../themePalette";
614
import type { OpenVsxThemeExtension } from "../../openVsxThemes";
715
import { ThemeImportDialog } from "./ThemeImportDialog";
816

@@ -54,3 +62,53 @@ describe("ThemeImportDialog", () => {
5462
);
5563
});
5664
});
65+
66+
const theme = (name: string, accent = "#3b82f6") => ({
67+
version: THEME_FILE_VERSION,
68+
name,
69+
appearance: "dark",
70+
colors: { accent },
71+
});
72+
73+
const themeFile = (name: string, accent?: string) =>
74+
new File([JSON.stringify(theme(name, accent))], `${name}.json`, { type: "application/json" });
75+
76+
it.each(["Update existing", "Keep both"])(
77+
"keeps batch failures visible after %s",
78+
async (choice) => {
79+
using _themes = {
80+
[Symbol.dispose]() {
81+
window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY);
82+
invalidateCustomThemes();
83+
},
84+
};
85+
installCustomTheme(parseThemeFile(theme("Dusk")));
86+
const onOpenChange = vi.fn();
87+
await using _screen = await render(
88+
<ThemeImportDialog
89+
open
90+
onOpenChange={onOpenChange}
91+
onImported={() => true}
92+
onImportedMany={() => {}}
93+
/>,
94+
);
95+
const input = document.querySelector<HTMLInputElement>('input[type="file"]')!;
96+
await userEvent.upload(input, [
97+
themeFile("Dawn"),
98+
themeFile("Dusk", "#f97316"),
99+
new File(["{"], "broken.json", { type: "application/json" }),
100+
]);
101+
102+
await expect.element(page.getByText("Already installed")).toBeVisible();
103+
await expect.element(page.getByText(/^broken\.json:/)).toBeVisible();
104+
expect(getCustomThemes().map((theme) => theme.label)).toContain("Dawn");
105+
await page.getByRole("button", { name: choice }).click();
106+
invalidateCustomThemes();
107+
const label = choice === "Update existing" ? "Dusk" : "Dusk (1)";
108+
expect(getCustomThemes().find((theme) => theme.label === label)?.colors).toEqual(
109+
parseThemeFile(theme("Dusk", "#f97316")).colors,
110+
);
111+
await expect.element(page.getByText(/^broken\.json:/)).toBeVisible();
112+
expect(onOpenChange).not.toHaveBeenCalledWith(false);
113+
},
114+
);

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,10 @@ function ThemeImportBody({
284284
}
285285
}
286286
if (installed.length > 0) onImportedMany(installed, { updated: false });
287-
if (failures.length > 0) {
288-
setError(failures.join("; "));
289-
} else if (conflicting.length > 0) {
287+
setError(failures.length > 0 ? failures.join("; ") : null);
288+
if (conflicting.length > 0) {
290289
setConflicts(conflicting);
291-
} else if (installed.length > 0) {
290+
} else if (installed.length > 0 && failures.length === 0) {
292291
onClose();
293292
}
294293
};
@@ -387,8 +386,8 @@ function ThemeImportBody({
387386
}
388387
if (resolved.length > 0) onImportedMany(resolved, { updated: mode === "update" });
389388
setConflicts(null);
390-
if (failures.length > 0) setError(failures.join("; "));
391-
else onClose();
389+
if (failures.length > 0) setError([error, ...failures].filter(Boolean).join("; "));
390+
else if (!error) onClose();
392391
};
393392

394393
const handleSubmit = () => {

0 commit comments

Comments
 (0)