diff --git a/apps/server/src/themes.test.ts b/apps/server/src/themes.test.ts index 43c7b4923a..abdca3adf5 100644 --- a/apps/server/src/themes.test.ts +++ b/apps/server/src/themes.test.ts @@ -1,7 +1,7 @@ import { ThemePaletteConfig, type ThemePaletteDefinition } from "@t3tools/contracts"; import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, it } from "@effect/vitest"; -import { Effect, FileSystem, Layer, Logger, Path, Schema } from "effect"; +import { Effect, FileSystem, Layer, Path, Schema } from "effect"; import { ServerConfig, type ServerConfigShape } from "./config"; import { Themes, ThemesLive } from "./themes"; @@ -120,7 +120,7 @@ it.layer(NodeServices.layer)("themes", (it) => { message: configState.issues[0]?.message ?? "", }, ]); - }).pipe(Effect.provide(makeThemesLayer()), Logger.withMinimumLogLevel("Fatal")), + }).pipe(Effect.provide(makeThemesLayer())), ); it.effect("persists valid custom themes without mutation", () => diff --git a/apps/web/src/lib/themePalettes.ts b/apps/web/src/lib/themePalettes.ts index 49a069d850..6e10c5634d 100644 --- a/apps/web/src/lib/themePalettes.ts +++ b/apps/web/src/lib/themePalettes.ts @@ -1,4 +1,8 @@ -import type { ThemePaletteDefinition, ThemeTokenName } from "@t3tools/contracts"; +import { + THEME_TOKEN_NAMES, + type ThemePaletteDefinition, + type ThemeTokenName, +} from "@t3tools/contracts"; export type ResolvedThemeMode = "light" | "dark"; export type ThemePreference = ResolvedThemeMode | "system"; @@ -202,11 +206,27 @@ function resolveThemePalette( label: input.label, description, source, - light: { ...DEFAULT_LIGHT_TOKENS, ...(input.light ?? {}) }, - dark: { ...DEFAULT_DARK_TOKENS, ...(input.dark ?? {}) }, + light: { ...DEFAULT_LIGHT_TOKENS, ...sanitizeThemeTokenOverrides(input.light) }, + dark: { ...DEFAULT_DARK_TOKENS, ...sanitizeThemeTokenOverrides(input.dark) }, } satisfies ThemePalette; } +function sanitizeThemeTokenOverrides(overrides: Record | undefined) { + const sanitized: ThemeTokenOverrides = {}; + if (!overrides) { + return sanitized; + } + + for (const tokenName of THEME_TOKEN_NAMES) { + const value = overrides[tokenName]; + if (typeof value === "string") { + sanitized[tokenName] = value; + } + } + + return sanitized; +} + const BUILT_IN_THEME_PALETTE_MAP = new Map( BUILT_IN_THEME_PALETTES.map((palette) => [palette.id, resolveThemePalette(palette, "built-in")]), ); diff --git a/apps/web/src/routes/_chat.settings.tsx b/apps/web/src/routes/_chat.settings.tsx index 4ced36d4b6..0d3b047148 100644 --- a/apps/web/src/routes/_chat.settings.tsx +++ b/apps/web/src/routes/_chat.settings.tsx @@ -433,8 +433,15 @@ function SettingsRouteView() {

Invalid custom theme entries

- {themeIssues.map((issue, index) => ( -

+ {themeIssues.map((issue) => ( +

{issue.kind === "themes.invalid-entry" ? `Entry ${issue.index + 1}: ${issue.message}` : issue.message} diff --git a/packages/contracts/src/theme.ts b/packages/contracts/src/theme.ts index 56b87eb57e..b475eb3e8e 100644 --- a/packages/contracts/src/theme.ts +++ b/packages/contracts/src/theme.ts @@ -44,10 +44,7 @@ const ThemeTokenValue = TrimmedNonEmptyString.check( Schema.isPattern(/^[^\n\r{};]+$/), ); -export const ThemeTokenNameSchema = Schema.Literals(THEME_TOKEN_NAMES); -export const ThemePaletteTokens = Schema.Record(ThemeTokenNameSchema, ThemeTokenValue).check( - Schema.isMaxLength(THEME_TOKEN_NAMES.length), -); +export const ThemePaletteTokens = Schema.Record(Schema.String, ThemeTokenValue); export type ThemePaletteTokens = typeof ThemePaletteTokens.Type; export const ThemePaletteDefinition = Schema.Struct({