@devries-cameron20 / t3code-1 / commits / 83e3c4f60d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): published themes keep their CSS when a saved theme shares the id (#37493)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Elias committed Nov 16, 2026 at 11:09 UTC 83e3c4f60da114220eac8d0b54c238e33defbab3
3 files changed +79 -23
apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx
+13 -7
@@ -65,15 +65,20 @@ describe("ThemeImportDialog", () => {
65 });
66 });
67
68 -const theme = (name: string, accent = "#3b82f6") => ({
68 +const theme = (name: string, accent = "#3b82f6", css?: string) => ({
69 version: THEME_FILE_VERSION,
70 name,
71 appearance: "dark",
72 colors: { accent },
73 + ...(css ? { css } : {}),
74 });
75
75 -const themeFile = (name: string, accent?: string) =>
76 - new File([JSON.stringify(theme(name, accent))], `${name}.json`, { type: "application/json" });
76 +const themeFile = (name: string, accent?: string, css?: string) =>
77 + new File([JSON.stringify(theme(name, accent, css))], `${name}.json`, {
78 + type: "application/json",
79 + });
80 +
81 +const DUSK_CSS = ".chat-header { height: 3rem; }";
82
83 it.each(["Update existing", "Keep both"])(
84 "keeps batch failures visible after %s",
@@ -97,7 +102,7 @@ it.each(["Update existing", "Keep both"])(
102 const input = document.querySelector<HTMLInputElement>('input[type="file"]')!;
103 await userEvent.upload(input, [
104 themeFile("Dawn"),
100 - themeFile("Dusk", "#f97316"),
105 + themeFile("Dusk", "#f97316", DUSK_CSS),
106 new File(["{"], "broken.json", { type: "application/json" }),
107 ]);
108
@@ -107,9 +112,10 @@ it.each(["Update existing", "Keep both"])(
112 await page.getByRole("button", { name: choice }).click();
113 invalidateCustomThemes();
114 const label = choice === "Update existing" ? "Dusk" : "Dusk (1)";
110 - expect(getCustomThemes().find((theme) => theme.label === label)?.colors).toEqual(
111 - parseThemeFile(theme("Dusk", "#f97316")).colors,
112 - );
115 + expect(getCustomThemes().find((theme) => theme.label === label)).toMatchObject({
116 + colors: parseThemeFile(theme("Dusk", "#f97316")).colors,
117 + css: DUSK_CSS,
118 + });
119 await expect.element(page.getByText(/^broken\.json:/)).toBeVisible();
120 expect(onOpenChange).not.toHaveBeenCalledWith(false);
121 },
apps/web/src/components/settings/ThemeImportDialog.tsx
+16 -16
@@ -39,6 +39,10 @@ function describeOversizedThemeFile(bytes: number): string | null {
39 return `That file is ${formatBytes(bytes)}. Theme files are only a few KB, so this one was not read (limit ${formatBytes(MAX_THEME_FILE_BYTES)}).`;
40 }
41
42 +function isThemeIdTaken(themeId: string): boolean {
43 + return getCustomThemes().some((existing) => existing.id === themeId);
44 +}
45 +
46 function escapeJsonHtml(value: string): string {
47 return value.replace(
48 /[&<>"']/g,
@@ -264,7 +268,7 @@ function ThemeImportBody({
268 const installed: ThemeDefinition[] = [];
269 const conflicting: ThemeDefinition[] = [];
270 for (const theme of pairVsCodeThemes(resolveThemeLabelCollisions(parsed))) {
267 - if (getCustomThemes().some((existing) => existing.id === theme.id)) {
271 + if (isThemeIdTaken(theme.id)) {
272 conflicting.push(theme);
273 continue;
274 }
@@ -325,28 +329,24 @@ function ThemeImportBody({
329 theme: ThemeDefinition,
330 preferredName?: string | null,
331 ): ThemeDefinition => {
328 - if (preferredName && preferredName.toLowerCase() !== theme.label.toLowerCase()) {
329 - const candidate = parseThemeFile({
332 + // The collection stays behind: updating a collection replaces every theme in it.
333 + const copyNamed = (name: string) =>
334 + parseThemeFile({
335 version: THEME_FILE_VERSION,
331 - name: preferredName.slice(0, 48),
336 + name,
337 appearance: theme.appearance,
338 colors: theme.colors,
339 ...(theme.variants ? { variants: theme.variants } : {}),
340 ...(theme.managed ? { managed: true } : {}),
341 + ...(theme.css ? { css: theme.css } : {}),
342 });
337 - if (!getCustomThemes().some((existing) => existing.id === candidate.id)) return candidate;
343 + if (preferredName && preferredName.toLowerCase() !== theme.label.toLowerCase()) {
344 + const candidate = copyNamed(preferredName.slice(0, 48));
345 + if (!isThemeIdTaken(candidate.id)) return candidate;
346 }
347 for (let copy = 1; copy < 100; copy += 1) {
340 - const candidate = parseThemeFile({
341 - version: THEME_FILE_VERSION,
342 - name: `${theme.label.slice(0, 48 - ` (${copy})`.length)} (${copy})`,
343 - appearance: theme.appearance,
344 - colors: theme.colors,
345 - ...(theme.variants ? { variants: theme.variants } : {}),
346 - ...(theme.managed ? { managed: true } : {}),
347 - });
348 - if (getCustomThemes().some((existing) => existing.id === candidate.id)) continue;
349 - return candidate;
348 + const candidate = copyNamed(`${theme.label.slice(0, 48 - ` (${copy})`.length)} (${copy})`);
349 + if (!isThemeIdTaken(candidate.id)) return candidate;
350 }
351 throw new Error(`Too many copies of "${theme.label}".`);
352 };
@@ -391,7 +391,7 @@ function ThemeImportBody({
391 }
392 try {
393 const theme = parseThemeImport(json);
394 - if (getCustomThemes().some((existing) => existing.id === theme.id)) {
394 + if (isThemeIdTaken(theme.id)) {
395 setError(null);
396 setConflicts([theme]);
397 return;
scripts/scenarios/theme-keep-both-copy-keeps-css.e2e.ts new
+50
@@ -0,0 +1,50 @@
1 +import { expect } from "e2e";
2 +
3 +import { test, WEB } from "./t3.ts";
4 +
5 +const themeJson = (css?: string) =>
6 + JSON.stringify({
7 + version: 1,
8 + name: "Nyx",
9 + // The scenario browser is in light mode, and a one-appearance theme only fills that half.
10 + appearance: "light",
11 + colors: { canvas: "#f4f1ff", accent: "#6d5ae6" },
12 + ...(css ? { css } : {}),
13 + });
14 +
15 +const NYX_CSS =
16 + ":root { --keep-both-marker: applied; } [data-settings-page-scroll] { outline: 8px solid #ff2d95; outline-offset: -8px; }";
17 +
18 +test(
19 + "Keep both on a theme import conflict keeps the imported theme's CSS",
20 + WEB,
21 + async ({ t3, app, screen, browser }) => {
22 + await t3.project("demo");
23 + await t3.open("/settings/appearance");
24 +
25 + const importTheme = async (json: string) => {
26 + await screen.getByRole("button", "Add theme", { exact: true }).tap();
27 + const dialog = screen.getByRole("dialog", "Add a theme");
28 + await dialog.getByRole("textbox", "Theme JSON").fill(json);
29 + await dialog.getByRole("button", "Add theme", { exact: true }).tap();
30 + return dialog;
31 + };
32 +
33 + await expect(await importTheme(themeJson())).toBeHidden();
34 +
35 + const dialog = await importTheme(themeJson(NYX_CSS));
36 + await expect(dialog.getByText("Already installed")).toBeVisible();
37 + await dialog.getByRole("button", "Keep both").tap();
38 + await expect(dialog).toBeHidden();
39 +
40 + await screen.getByRole("button", "Use Nyx (1) theme").tap();
41 + await app.screenshot("keep-both-copy-selected");
42 + await expect
43 + .poll(() =>
44 + browser.evaluate(() =>
45 + getComputedStyle(document.documentElement).getPropertyValue("--keep-both-marker").trim(),
46 + ),
47 + )
48 + .toBe("applied");
49 + },
50 +);