diff --git a/apps/web/src/components/settings/ThemeSettings.tsx b/apps/web/src/components/settings/ThemeSettings.tsx index 9e59c2ef3f30a..2ee8e65bba9aa 100644 --- a/apps/web/src/components/settings/ThemeSettings.tsx +++ b/apps/web/src/components/settings/ThemeSettings.tsx @@ -19,6 +19,7 @@ import { getThemeModes, removeCustomThemes, serializeThemeFile, + themeFileName, type ThemeAppearance, type ThemeDefinition, type ThemeHalves, @@ -862,7 +863,7 @@ export function ThemeLibrary({ activeModesFor={pickedModesFor} key={collectionId} onDownload={(customTheme) => - downloadThemeFile(`${customTheme.id}.json`, serializeThemeFile(customTheme)) + downloadThemeFile(themeFileName(customTheme), serializeThemeFile(customTheme)) } onDuplicate={(customTheme) => openThemeEditor({ diff --git a/apps/web/src/themePalette.test.ts b/apps/web/src/themePalette.test.ts index dd33895b58417..264e5252bdad1 100644 --- a/apps/web/src/themePalette.test.ts +++ b/apps/web/src/themePalette.test.ts @@ -25,6 +25,7 @@ import { resolveDesktopTheme, resolveThemeAppearance, serializeThemeFile, + themeFileName, T3_CHAT_THEME, GROVE_THEME, updateCustomTheme, @@ -77,6 +78,18 @@ describe("theme files", () => { expect(parseThemeFile({ ...file, name: " 夜 " }).id).toBe(night.id); }); + it("names an exported file after the current label and keeps the id in the file", () => { + const copy = parseThemeFile({ + version: THEME_FILE_VERSION, + name: "T3 Code copy", + appearance: "dark", + colors: { canvas: "#101820" }, + }); + const renamed = { ...copy, label: "T3 Code 2" }; + expect(themeFileName(renamed)).toBe("t3-code-2.json"); + expect(JSON.parse(serializeThemeFile(renamed)).id).toBe("t3-code-copy"); + }); + it("keeps built-in and standard search pairs readable and distinct from inline code", () => { const toOklab = converter("oklab"); const distance = (first: string, second: string) => { diff --git a/apps/web/src/themePalette.ts b/apps/web/src/themePalette.ts index d04e7e1671835..9aa0c25580121 100644 --- a/apps/web/src/themePalette.ts +++ b/apps/web/src/themePalette.ts @@ -1634,6 +1634,11 @@ export function renameTheme(theme: ThemeDefinition, name: string): ThemeDefiniti }); } +// A theme keeps its id across renames. +export function themeFileName(theme: ThemeDefinition): string { + return `${themeIdFromName(theme.label)}.json`; +} + export function serializeThemeFile(theme: ThemeDefinition): string { const canonicalTheme = canonicalizeThemeDefinition(theme); const file: ThemeFile = {