@devries-cameron20 / t3code Mirror · read-only / commits / 077b206b33
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 08:30 UTC

fix(web): same-named themes renamed on batch import keep their CSS (#38139)

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

Wout Stiens committed Nov 17, 2026 at 14:59 UTC 077b206b33b63e664f5f68dc1ad675d76bd2c730
5 files changed +82 -26
apps/web/src/components/settings/ThemeImportDialog.tsx
+7 -15
@@ -7,9 +7,8 @@ import { cn } from "../../lib/utils";
7 import {
8 getCustomThemes,
9 installCustomTheme,
10 - parseThemeFile,
10 removeCustomTheme,
12 - THEME_FILE_VERSION,
11 + renameTheme,
12 updateCustomTheme,
13 type ThemeDefinition,
14 } from "../../themePalette";
@@ -343,23 +342,16 @@ function ThemeImportBody({
342 theme: ThemeDefinition,
343 preferredName?: string | null,
344 ): ThemeDefinition => {
346 - // The collection stays behind: updating a collection replaces every theme in it.
347 - const copyNamed = (name: string) =>
348 - parseThemeFile({
349 - version: THEME_FILE_VERSION,
350 - name,
351 - appearance: theme.appearance,
352 - colors: theme.colors,
353 - ...(theme.variants ? { variants: theme.variants } : {}),
354 - ...(theme.managed ? { managed: true } : {}),
355 - ...(theme.css ? { css: theme.css } : {}),
356 - });
345 + // renameTheme leaves the collection behind: updating a collection replaces every theme in it.
346 if (preferredName && preferredName.toLowerCase() !== theme.label.toLowerCase()) {
358 - const candidate = copyNamed(preferredName.slice(0, 48));
347 + const candidate = renameTheme(theme, preferredName.slice(0, 48));
348 if (!isThemeIdTaken(candidate.id)) return candidate;
349 }
350 for (let copy = 1; copy < 100; copy += 1) {
362 - const candidate = copyNamed(`${theme.label.slice(0, 48 - ` (${copy})`.length)} (${copy})`);
351 + const candidate = renameTheme(
352 + theme,
353 + `${theme.label.slice(0, 48 - ` (${copy})`.length)} (${copy})`,
354 + );
355 if (!isThemeIdTaken(candidate.id)) return candidate;
356 }
357 throw new Error(`Too many copies of "${theme.label}".`);
apps/web/src/themePalette.ts
+13
@@ -1581,6 +1581,19 @@ export function parseThemeFile(value: unknown): ThemeDefinition {
1581 };
1582 }
1583
1584 +/** A copy of `theme` under `name` and the id it derives. The collection stays behind. */
1585 +export function renameTheme(theme: ThemeDefinition, name: string): ThemeDefinition {
1586 + return parseThemeFile({
1587 + version: THEME_FILE_VERSION,
1588 + name,
1589 + appearance: theme.appearance,
1590 + colors: theme.colors,
1591 + ...(theme.variants ? { variants: theme.variants } : {}),
1592 + ...(theme.managed ? { managed: true } : {}),
1593 + ...(theme.css ? { css: theme.css } : {}),
1594 + });
1595 +}
1596 +
1597 export function serializeThemeFile(theme: ThemeDefinition): string {
1598 const canonicalTheme = canonicalizeThemeDefinition(theme);
1599 const file: ThemeFile = {
apps/web/src/vscodeThemeImport.test.ts
+8 -3
@@ -514,22 +514,27 @@ describe("VS Code theme import", () => {
514
515 it("tells same-named variants apart by their file names", () => {
516 // Both Dracula theme files declare the same internal name.
517 - const dracula = (bg: string) =>
518 - parseVsCodeThemeFile({
517 + const css = ".app { outline: 1px solid red; }";
518 + const dracula = (bg: string) => ({
519 + ...parseVsCodeThemeFile({
520 name: "Dracula",
521 type: "dark",
522 colors: { "editor.background": bg, "editor.foreground": "#f8f8f2" },
522 - });
523 + }),
524 + css,
525 + });
526 const themes = resolveThemeLabelCollisions([
527 { theme: dracula("#282a36"), sourceName: "dracula.json" },
528 { theme: dracula("#22232e"), sourceName: "dracula-soft.json" },
529 ]);
530 expect(themes.map((theme) => theme.label)).toEqual(["Dracula", "Dracula Soft"]);
531 expect(themes.map((theme) => theme.id)).toEqual(["dracula", "dracula-soft"]);
532 + expect(themes.map((theme) => theme.css)).toEqual([css, css]);
533 const numbered = resolveThemeLabelCollisions([
534 { theme: dracula("#282a36") },
535 { theme: dracula("#22232e") },
536 ]);
537 expect(numbered.map((theme) => theme.label)).toEqual(["Dracula", "Dracula 2"]);
538 + expect(numbered.map((theme) => theme.css)).toEqual([css, css]);
539 });
540 });
apps/web/src/vscodeThemeImport.ts
+2 -8
@@ -7,6 +7,7 @@ import {
7 isReservedThemeId,
8 parseThemeFile,
9 readableThemeColorOn,
10 + renameTheme,
11 themeColorToHex,
12 themeIdFromName,
13 THEME_FILE_VERSION,
@@ -451,14 +452,7 @@ export function resolveThemeLabelCollisions(
452 ): ReadonlyArray<ThemeDefinition> {
453 const rename = (theme: ThemeDefinition, name: string): ThemeDefinition | null => {
454 try {
454 - return parseThemeFile({
455 - version: THEME_FILE_VERSION,
456 - name: name.slice(0, 48),
457 - appearance: theme.appearance,
458 - colors: theme.colors,
459 - ...(theme.variants ? { variants: theme.variants } : {}),
460 - ...(theme.managed ? { managed: true } : {}),
461 - });
455 + return renameTheme(theme, name.slice(0, 48));
456 } catch {
457 return null;
458 }
scripts/scenarios/theme-batch-renamed-css.e2e.ts new
+52
@@ -0,0 +1,52 @@
1 +import { expect } from "e2e";
2 +
3 +import { test, WEB } from "./t3.ts";
4 +
5 +test(
6 + "Renaming same-named themes during a batch import preserves their CSS",
7 + WEB,
8 + async ({ t3, app, screen, browser }) => {
9 + await t3.project("demo");
10 + await t3.open("/settings/appearance");
11 + await screen.getByRole("button", "Add theme", { exact: true }).tap();
12 +
13 + await browser.evaluate(() => {
14 + const files = new DataTransfer();
15 + for (const name of ["nyx-one.json", "nyx-two.json"]) {
16 + files.items.add(
17 + new File(
18 + [
19 + JSON.stringify({
20 + version: 1,
21 + name: "Nyx",
22 + appearance: "light",
23 + colors: { canvas: "#f4f1ff", accent: "#6d5ae6" },
24 + css: "[data-settings-page-scroll] { outline: 8px solid #ff2d95; outline-offset: -8px; }",
25 + }),
26 + ],
27 + name,
28 + { type: "application/json" },
29 + ),
30 + );
31 + }
32 + const target = document.querySelector('input[type="file"]')?.parentElement;
33 + if (!target) throw new Error("No theme file drop target");
34 + target.dispatchEvent(
35 + new DragEvent("drop", { dataTransfer: files, bubbles: true, cancelable: true }),
36 + );
37 + return null;
38 + });
39 +
40 + await screen.getByRole("button", "Use Nyx One theme").tap();
41 + await app.screenshot("renamed-batch-theme-selected");
42 + await expect
43 + .poll(() =>
44 + browser.evaluate(() => {
45 + const page = document.querySelector("[data-settings-page-scroll]");
46 + if (!page) throw new Error("No Appearance settings page");
47 + return getComputedStyle(page).outlineWidth;
48 + }),
49 + )
50 + .toBe("8px");
51 + },
52 +);