Skip to content

Commit b211fa4

Browse files
committed
fix(web): omit published themes without usable colors
1 parent 63b08fc commit b211fa4

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

‎apps/web/src/hooks/useEnvironmentTheme.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,46 @@ describe("environment themes", () => {
9797
expect(definitions.map((definition) => definition.id)).toEqual(["nightfall"]);
9898
});
9999

100+
it("drops published palettes with no usable colors", () => {
101+
const theme = { id: "invalid", name: "Invalid", appearance: "dark" } as const;
102+
const definitions = publishedThemeDefinitions([
103+
{ ...theme, colors: { canvas: "not-a-color" } },
104+
{ ...theme, id: "unknown-roles", colors: { futureRole: "#ffffff" } },
105+
{
106+
...theme,
107+
id: "ignored-variant",
108+
colors: { canvas: "not-a-color" },
109+
variants: { dark: { canvas: "#112233" } },
110+
},
111+
]);
112+
113+
expect(definitions).toEqual([]);
114+
});
115+
116+
it("keeps seeds, partial palettes, and usable alternate appearances", () => {
117+
const theme = { name: "Shared", appearance: "dark" } as const;
118+
const definitions = publishedThemeDefinitions([
119+
NIGHTFALL_THEME,
120+
{
121+
...theme,
122+
id: "partial",
123+
colors: { canvas: "not-a-color", text: "#ffffff", futureRole: "#ffffff" },
124+
},
125+
{
126+
...theme,
127+
id: "light-variant",
128+
colors: { canvas: "not-a-color" },
129+
variants: { light: { canvas: "#eff1f5" } },
130+
},
131+
]);
132+
133+
expect(definitions.map((definition) => definition.id)).toEqual([
134+
"nightfall",
135+
"partial",
136+
"light-variant",
137+
]);
138+
});
139+
100140
// A machine may publish roles a newer client added; an older one has to
101141
// ignore them rather than render a broken palette.
102142
it("ignores published roles this build does not render", () => {

‎apps/web/src/hooks/useEnvironmentTheme.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,25 @@ export function environmentThemeDefinition(theme: EnvironmentTheme): ThemeDefini
7272
}
7373

7474
/**
75-
* The published set as library entries. Reserved ids are dropped here rather
75+
* Published palettes this client can render. Reserved ids are dropped here rather
7676
* than rendered: a published `t3-iris.json` would show this palette on its
7777
* card while "Use" resolved the built-in, and a published `dark.json` would
7878
* capture everyone whose stored preference is the stock `"dark"`.
7979
*/
8080
export function publishedThemeDefinitions(
8181
themes: ReadonlyArray<EnvironmentTheme>,
8282
): ReadonlyArray<ThemeDefinition> {
83-
return themes.filter((theme) => !isReservedThemeId(theme.id)).map(environmentThemeDefinition);
83+
return themes
84+
.filter((theme) => {
85+
if (isReservedThemeId(theme.id)) return false;
86+
if (theme.canvas !== undefined && theme.accent !== undefined) return true;
87+
const otherAppearance = theme.appearance === "dark" ? "light" : "dark";
88+
return [theme.colors, theme.variants?.[otherAppearance]].some(
89+
(colors) =>
90+
colors !== undefined && Object.keys(lenientThemeColorOverrides(colors)).length > 0,
91+
);
92+
})
93+
.map(environmentThemeDefinition);
8494
}
8595

8696
/** The published themes as library entries; empty while none are published. */

‎docs/user/environment-theme.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ out keep their generated value. A role this version of T3 Code does not know is
8585
than rejected, so publishing a role added by a newer release is safe. An `id` inside the file is
8686
ignored — the filename decides.
8787

88+
A theme with no usable colors is not listed on that client.
89+
8890
Write each file atomically — write a temporary file beside it and rename — so T3 Code never reads
8991
a half-written theme. An unreadable or invalid file is simply not published; the machine's other
9092
themes are unaffected.

0 commit comments

Comments
 (0)