Skip to content

Commit 93ff9a9

Browse files
feat(studio): fail the suite on a class that resolves to nothing (#3623)
* feat(studio): fail the suite on a class that resolves to nothing Tailwind silently drops a class it cannot compile, so `rounded-button` renders as no radius at all and nothing goes red. Two tests close that: - the token gate compiles Studio's entry stylesheet with every class the source claims and reports `file: class` for anything that produces no selector. Tailwind is the judge, so there is no allowlist. - the hex ratchet counts colour literals per file against a committed baseline. It fails on a rise, and on a fall it prints the command that banks the lower number. The baseline is only written under a named flag, never as a side effect of a run. The gate's first run found seven names the markup has always asked for and no config has ever defined: rounded-button, shadow-btn-primary, bg-surface-hover, bg-accent-red, ease-standard, text-2xs and two panel backgrounds. Each is added to theme.css, the semantic ones by role and the rest as deprecated aliases for the sweep to remove. It also found a dead state class on the timeline clip, styled nowhere, which is deleted. * fix(studio): gate a class by where it is used, not what it is called The extractor treated a string as a class candidate only when its binding matched Styles/Classes/ClassName(s), so the same twelve classes were gated in `sizeStyles` and invisible in `buttonSizes`. A name is not a contract. Candidate-ness now follows one file's data flow: an identifier used inside a className attribute or a class-building call marks whatever is bound to it as classes, under any name. A subscript is excluded, so the key of `variantStyles[variant]` is not mistaken for a class list. The name-based anchor stays for the map whose only consumer is another module. The sweep this opened found one class no config has ever defined: the automation menu's hover row asked for a background that compiled to nothing, and now uses the token the rest of that row already uses. * fix(studio): the colour ratchet counts code, not colour-shaped numbers in comments * fix(studio): draw the drop preview and preview guides from theme colours instead of literals * chore(studio): bank the lower colour-literal baseline now that comments are not counted * docs(studio): shorten the style test and extractor comments to fit the comment gate * fix(studio): the colour ratchet keeps strings when stripping comments * fix(studio): escape every regex metacharacter when following a bound class list * fix(studio): find a class list bound to a dollar-prefixed name * fix(studio): style source paths use forward slashes on every platform
1 parent 1dce615 commit 93ff9a9

14 files changed

Lines changed: 882 additions & 23 deletions

‎packages/studio/src/components/editor/PreviewGuides.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface PreviewGuidesProps {
88
}
99

1010
const TICKS = Array.from({ length: 11 }, (_, i) => i * 10);
11-
const INK = "rgba(255,255,255,0.7)";
11+
const INK = "color-mix(in srgb, white 70%, transparent)";
1212

1313
/** Ruler and safe-margin boxes drawn over the preview pane, never inside the composition. */
1414
export const PreviewGuides = memo(function PreviewGuides({ iframeRef }: PreviewGuidesProps) {

‎packages/studio/src/player/components/AutomationSelectionMenu.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const AutomationSelectionMenu = memo(function AutomationSelectionMenu({
2929
}: AutomationSelectionMenuProps) {
3030
const menuRef = useContextMenuDismiss(onClose);
3131
const row =
32-
"block w-full px-2 py-1 text-left text-[11px] text-panel-text-1 hover:bg-panel-bg-3 disabled:opacity-40";
32+
"block w-full px-2 py-1 text-left text-[11px] text-panel-text-1 hover:bg-panel-hover disabled:opacity-40";
3333
// Same edge-clamping precedent as TrackGapContextMenu: without it a
3434
// right-click near the bottom/right of the timeline renders this menu
3535
// partially off-screen.

‎packages/studio/src/player/components/TimelineCanvas.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ export const TimelineCanvas = memo(function TimelineCanvas(props: TimelineCanvas
179179
left: props.contentOrigin + draggedClip.previewStart * props.pps,
180180
width: Math.max(draggedClip.element.duration * props.pps, 4),
181181
height: draggedClipHeight,
182-
border: "1px solid rgba(60,230,172,0.55)",
183-
background: "rgba(60,230,172,0.12)",
182+
border: "1px solid color-mix(in srgb, var(--color-accent) 55%, transparent)",
183+
background: "color-mix(in srgb, var(--color-accent) 12%, transparent)",
184184
borderRadius: 4,
185185
zIndex: 30,
186186
}}
@@ -199,8 +199,8 @@ export const TimelineCanvas = memo(function TimelineCanvas(props: TimelineCanvas
199199
left: props.contentOrigin + props.dropPreview.start * props.pps,
200200
width: DROP_PREVIEW_SECONDS * props.pps,
201201
height: TRACK_H - CLIP_Y * 2,
202-
border: "1px solid rgba(60,230,172,0.55)",
203-
background: "rgba(60,230,172,0.12)",
202+
border: "1px solid color-mix(in srgb, var(--color-accent) 55%, transparent)",
203+
background: "color-mix(in srgb, var(--color-accent) 12%, transparent)",
204204
borderRadius: 4,
205205
zIndex: 30,
206206
}}

‎packages/studio/src/player/components/TimelineClip.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export const TimelineClip = memo(function TimelineClip({
7171
isSelected ? "is-selected" : "",
7272
isHovered ? "is-hovered" : "",
7373
isDragging ? "is-dragging" : "",
74-
showDefaultText ? "" : "is-micro",
7574
isAudioTimelineElement(el) ? "is-audio" : "",
7675
]
7776
.filter((className) => className.length > 0)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { describe, expect, it } from "vitest";
2+
import { extractClassCandidates } from "./classCandidates";
3+
4+
function bases(source: string): string[] {
5+
return extractClassCandidates(source)
6+
.map((candidate) => candidate.base)
7+
.sort();
8+
}
9+
10+
describe("extractClassCandidates", () => {
11+
it("reads a plain className attribute", () => {
12+
expect(bases(`<div className="text-center border-dashed" />`)).toEqual([
13+
"border-dashed",
14+
"text-center",
15+
]);
16+
});
17+
18+
it("reads every string a class-building call is given", () => {
19+
const source = `<div className={cn("flex", open && "bg-surface", { "text-accent": on })} />`;
20+
21+
expect(bases(source)).toEqual(["bg-surface", "flex", "text-accent"]);
22+
});
23+
24+
it("reads a class map that never touches a className literal", () => {
25+
// The shape Studio's primitives use: the utility only reaches markup
26+
// through a lookup, so an attribute-only reader would miss it entirely.
27+
const source = `const sizeStyles: Record<ButtonSize, string> = {
28+
sm: "h-7 px-2.5 rounded-button",
29+
};`;
30+
31+
expect(bases(source)).toEqual(["h-7", "px-2.5", "rounded-button"]);
32+
});
33+
34+
it("reads a class map whose name says nothing about classes", () => {
35+
// The defect this replaced: candidate-ness was decided by the binding's
36+
// name, so the same classes were gated in `sizeStyles` and invisible in
37+
// `buttonSizes`. What makes them classes is where they are used.
38+
const source = `const fooSizes = { md: "h-ctl rounded-hologram" };
39+
const Foo = ({ size }) => <span className={cn(fooSizes[size])} />;`;
40+
41+
expect(bases(source)).toEqual(["h-ctl", "rounded-hologram"]);
42+
});
43+
44+
it("follows an identifier that contains a dollar sign", () => {
45+
const source = `const $cls = "flex-none";\nconst a = <div className={$cls} />;`;
46+
47+
expect(bases(source)).toEqual(["flex-none"]);
48+
});
49+
50+
it("does not read a lookup key's default value as a class", () => {
51+
// `variant` is the key, not the class list, so the default it falls back
52+
// to is a map entry name and never reaches markup.
53+
const source = `const map = { ghost: "bg-transparent" };
54+
const Foo = ({ variant = "ghost" }) => <span className={map[variant]} />;`;
55+
56+
expect(bases(source)).toEqual(["bg-transparent"]);
57+
});
58+
59+
it("leaves a lookup table alone when nothing uses it as a class", () => {
60+
const source = `const labels = { md: "Medium size" };
61+
const Foo = () => <span title={labels.md} />;`;
62+
63+
expect(bases(source)).toEqual([]);
64+
});
65+
66+
it("drops the template chunk that touches an interpolation", () => {
67+
expect(bases("<div className={`w-${i} flex`} />")).toEqual(["flex"]);
68+
});
69+
70+
it("keeps a chunk that whitespace separates from the interpolation", () => {
71+
expect(bases("<div className={`${base} flex `} />")).toEqual(["flex"]);
72+
});
73+
74+
it("strips variant prefixes, including bracketed ones", () => {
75+
const source = `<div className="hover:bg-surface/50 md:group-data-[open]:text-accent" />`;
76+
77+
expect(bases(source)).toEqual(["bg-surface/50", "text-accent"]);
78+
});
79+
80+
it("flags bracketed arbitrary values so the sweep can count them", () => {
81+
const found = extractClassCandidates(`<div className="text-[11px] text-center" />`);
82+
83+
expect(found.filter((candidate) => candidate.arbitrary).map((c) => c.raw)).toEqual([
84+
"text-[11px]",
85+
]);
86+
});
87+
88+
it("ignores strings that are not class lists", () => {
89+
const source = `const styles = getComputedStyle(el);
90+
const label = "Export video";
91+
log("failed to open the project file");`;
92+
93+
expect(bases(source)).toEqual([]);
94+
});
95+
96+
it("does not read past the end of a class region", () => {
97+
const source = `<div className="flex" title="Export video" />`;
98+
99+
expect(bases(source)).toEqual(["flex"]);
100+
});
101+
102+
it("survives an unterminated region without hanging", () => {
103+
expect(bases(`<div className={cn("flex",`)).toEqual(["flex"]);
104+
});
105+
});

0 commit comments

Comments
 (0)