The best way to control Claude Code, Codex and more from any computer or phone
fix(web): give non-Latin theme names distinct stable ids (#23162)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 31, 2026 at 21:25 UTC
bc799c4ba55a85b855083da53d3674153e40a08b
2 files changed
+22
-4
apps/web/src/themePalette.test.ts
+11
@@ -61,6 +61,17 @@ function contrastRatio(first: string, second: string): number {
61
}
62
63
describe("theme files", () => {
64
+ it("gives non-Latin theme names distinct stable ids", () => {
65
+ const file = {
66
+ version: THEME_FILE_VERSION,
67
+ appearance: "dark",
68
+ colors: { canvas: "#101820" },
69
+ };
70
+ const night = parseThemeFile({ ...file, name: "夜" });
71
+ expect(parseThemeFile({ ...file, name: "朝" }).id).not.toBe(night.id);
72
+ expect(parseThemeFile({ ...file, name: " 夜 " }).id).toBe(night.id);
73
+ });
74
+
75
it("keeps built-in and standard search pairs readable and distinct from inline code", () => {
76
const toOklab = converter("oklab");
77
const distance = (first: string, second: string) => {
apps/web/src/themePalette.ts
+11
-4
@@ -1220,13 +1220,20 @@ export function getThemePreferenceMode(theme: ThemePreference): ThemeAppearance
1220
}
1221
1222
export function themeIdFromName(name: string): string {
1223
- const normalized = name
1224
- .trim()
1225
- .toLowerCase()
1223
+ const label = name.trim().toLowerCase();
1224
+ const normalized = label
1225
.replace(/[^a-z0-9]+/g, "-")
1226
.replace(/^-+|-+$/g, "")
1227
.slice(0, 48);
1229
- return normalized || "custom-theme";
1228
+ if (normalized || !label) return normalized || "custom-theme";
1229
+
1230
+ // Names without ASCII letters or digits still need independent, stable ids.
1231
+ let hash = 2_166_136_261;
1232
+ for (let index = 0; index < label.length; index += 1) {
1233
+ hash ^= label.charCodeAt(index);
1234
+ hash = Math.imul(hash, 16_777_619);
1235
+ }
1236
+ return `theme-${(hash >>> 0).toString(36)}`;
1237
}
1238
1239
export class ThemeLibraryStorageError extends Schema.TaggedError<ThemeLibraryStorageError>()(