Skip to content

Commit b9ec38a

Browse files
authored
fix(ui): resolve undefined --panel-2 token and harden the theme-token guard (#113776)
The skills page ClawHub verdict callout referenced var(--panel-2), which is defined nowhere, silently dropping its background; use the canonical --panel-strong tier. Extend base-theme-tokens.node.test.ts to every alias name this bug class has produced (--success/--warning/--panel-2 included) and scan all of ui/src including TS inline styles and Lit css templates, not just the styles directory. Codify the real spacing-scale policy in base.css: settings surfaces use --space-*, elsewhere raw px is grandfathered and migrates opportunistically.
1 parent 0a2a629 commit b9ec38a

3 files changed

Lines changed: 31 additions & 15 deletions

File tree

‎ui/src/pages/skills/view.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ function renderInstalledClawHubOverview(
782782
return html`
783783
<div
784784
class="callout"
785-
style="display: grid; gap: 8px; border-color: var(--border); background: var(--panel-2);"
785+
style="display: grid; gap: 8px; border-color: var(--border); background: var(--panel-strong);"
786786
>
787787
<div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
788788
<span class="chip ${verdictChipClass(verdict)}">${verdictLabel(verdict)}</span>

‎ui/src/styles/base-theme-tokens.node.test.ts‎

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,32 @@ import { fileURLToPath } from "node:url";
44
import { describe, expect, it } from "vitest";
55

66
const stylesDir = path.dirname(fileURLToPath(import.meta.url));
7+
const uiSrcDir = path.dirname(stylesDir);
8+
// Every alias name this bug class has produced so far, mapped to the canonical
9+
// token. Undefined names silently drop declarations (or invalidate color-mix),
10+
// so new aliases must be added to base.css, never invented at use sites.
711
const undefinedTokenMappings = {
812
"bg-subtle": "bg-muted",
913
"border-subtle": "border",
1014
fg: "text",
1115
foreground: "text",
16+
"panel-2": "panel-strong",
17+
success: "ok",
1218
surface: "panel",
1319
"text-muted": "muted",
20+
warning: "warn",
21+
"warning-subtle": "warn-subtle",
1422
} as const;
1523

16-
function collectCssFiles(directory: string): string[] {
24+
function collectFiles(directory: string, extensions: readonly string[]): string[] {
1725
return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
1826
const entryPath = path.join(directory, entry.name);
1927
if (entry.isDirectory()) {
20-
return collectCssFiles(entryPath);
28+
return entry.name === "node_modules" ? [] : collectFiles(entryPath, extensions);
2129
}
22-
return entry.isFile() && entry.name.endsWith(".css") ? [entryPath] : [];
30+
return entry.isFile() && extensions.some((extension) => entry.name.endsWith(extension))
31+
? [entryPath]
32+
: [];
2333
});
2434
}
2535

@@ -40,16 +50,20 @@ describe("Control UI base theme tokens", () => {
4050
`var\\(--(?:${undefinedTokens.join("|")})(?:\\s*\\)|\\s*,)`,
4151
"u",
4252
);
43-
const violations = collectCssFiles(stylesDir).flatMap((filePath) =>
44-
fs
45-
.readFileSync(filePath, "utf8")
46-
.split("\n")
47-
.flatMap((line, index) =>
48-
referencePattern.test(line)
49-
? [`${path.relative(stylesDir, filePath)}:${index + 1}: ${line.trim()}`]
50-
: [],
51-
),
52-
);
53+
// Inline style attributes and Lit css templates hit this class too
54+
// (var(--panel-2) shipped in a TS template), so scan all of ui/src.
55+
const violations = collectFiles(uiSrcDir, [".css", ".ts"])
56+
.filter((filePath) => !filePath.endsWith(".test.ts"))
57+
.flatMap((filePath) =>
58+
fs
59+
.readFileSync(filePath, "utf8")
60+
.split("\n")
61+
.flatMap((line, index) =>
62+
referencePattern.test(line)
63+
? [`${path.relative(uiSrcDir, filePath)}:${index + 1}: ${line.trim()}`]
64+
: [],
65+
),
66+
);
5367

5468
expect(violations).toEqual([]);
5569
});

‎ui/src/styles/base.css‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@
137137
--shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.5);
138138
--shadow-glow: 0 0 24px var(--accent-glow);
139139

140-
/* Spacing scale - use these instead of hardcoded px for padding/gap */
140+
/* Spacing scale. Settings surfaces use these (see
141+
ui/docs/design-system/settings-design.md); elsewhere raw px padding/gap is
142+
grandfathered — adopt the scale when rewriting a rule, don't mass-migrate. */
141143
--space-1: 4px;
142144
--space-2: 8px;
143145
--space-3: 12px;

0 commit comments

Comments
 (0)