Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

chore(ui): check transition-[…] lists cover v4 translate/scale/rotate (MUL-9967) (#11300)

Jiayuan Zhang912c3183b3e8
diff --git a/.github/actions/frontend-quality/action.yml b/.github/actions/frontend-quality/action.yml
index d5f6d4e617..ef73ea2cd1 100644
--- a/.github/actions/frontend-quality/action.yml
+++ b/.github/actions/frontend-quality/action.yml
@@ -17,6 +17,10 @@ runs:
shell: bash
run: node scripts/check-ui-radius-tokens.mjs
+ - name: Check UI transition properties
+ shell: bash
+ run: node scripts/check-ui-transition-properties.mjs
+
- name: Check shared dependencies use the pnpm catalog
shell: bash
run: node scripts/check-dependency-catalog.mjs
diff --git a/package.json b/package.json
index 64a1542252..28b2020f00 100644
--- a/package.json
+++ b/package.json
@@ -29,6 +29,7 @@
"knip": "knip",
"check:ui-exports": "node scripts/check-ui-wildcard-exports.mjs",
"check:ui-radii": "node scripts/check-ui-radius-tokens.mjs",
+ "check:ui-transitions": "node scripts/check-ui-transition-properties.mjs",
"check:deps-catalog": "node scripts/check-dependency-catalog.mjs",
"theme:check": "node scripts/theme-check.mjs",
"theme:preview": "node scripts/theme-preview.mjs",
diff --git a/packages/ui/components/common/reaction-bar.tsx b/packages/ui/components/common/reaction-bar.tsx
index 0aa73785ba..083cec4d81 100644
--- a/packages/ui/components/common/reaction-bar.tsx
+++ b/packages/ui/components/common/reaction-bar.tsx
@@ -79,7 +79,7 @@ function ReactionBar({
type="button"
onClick={() => onToggle(g.emoji)}
className={cn(
- "inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-caption transition-[background-color,border-color,color,transform] duration-100 ease-[cubic-bezier(0.23,1,0.32,1)] hover:bg-brand/15 active:scale-95 motion-reduce:transition-none motion-reduce:active:scale-100",
+ "inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-caption transition-[background-color,border-color,color,scale] duration-100 ease-[cubic-bezier(0.23,1,0.32,1)] hover:bg-brand/15 active:scale-95 motion-reduce:transition-none motion-reduce:active:scale-100",
g.reacted
? "border-brand/30 bg-brand/8 text-brand"
: "border-brand/10 bg-brand/4 text-muted-foreground",
diff --git a/packages/ui/components/ui/button.tsx b/packages/ui/components/ui/button.tsx
index 252e8e6f20..cae3e72a25 100644
--- a/packages/ui/components/ui/button.tsx
+++ b/packages/ui/components/ui/button.tsx
@@ -6,7 +6,7 @@ import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@multica/ui/lib/utils"
const buttonVariants = cva(
- "group/button inline-flex shrink-0 items-center justify-center rounded-button border border-transparent bg-clip-padding text-body font-medium whitespace-nowrap transition-[color,background-color,border-color,box-shadow,transform] outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4.5",
+ "group/button inline-flex shrink-0 items-center justify-center rounded-button border border-transparent bg-clip-padding text-body font-medium whitespace-nowrap transition-[color,background-color,border-color,box-shadow,translate] outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4.5",
{
variants: {
variant: {
diff --git a/packages/ui/components/ui/checkbox.tsx b/packages/ui/components/ui/checkbox.tsx
index 8880530881..eae54daf75 100644
--- a/packages/ui/components/ui/checkbox.tsx
+++ b/packages/ui/components/ui/checkbox.tsx
@@ -18,7 +18,7 @@ function Checkbox({ className, indeterminate, ...props }: CheckboxPrimitive.Root
>
<CheckboxPrimitive.Indicator
data-slot="checkbox-indicator"
- className="grid place-content-center text-current transition-[transform,opacity] duration-100 ease-[cubic-bezier(0.23,1,0.32,1)] data-[starting-style]:scale-75 data-[starting-style]:opacity-0 data-[ending-style]:scale-75 data-[ending-style]:opacity-0 motion-reduce:transition-none [&>svg]:size-3.5"
+ className="grid place-content-center text-current transition-[scale,opacity] duration-100 ease-[cubic-bezier(0.23,1,0.32,1)] data-[starting-style]:scale-75 data-[starting-style]:opacity-0 data-[ending-style]:scale-75 data-[ending-style]:opacity-0 motion-reduce:transition-none [&>svg]:size-3.5"
>
{indeterminate ? <MinusIcon /> : <CheckIcon />}
</CheckboxPrimitive.Indicator>
diff --git a/packages/ui/components/ui/sidebar.tsx b/packages/ui/components/ui/sidebar.tsx
index 392fc370d8..a70e17afe1 100644
--- a/packages/ui/components/ui/sidebar.tsx
+++ b/packages/ui/components/ui/sidebar.tsx
@@ -618,7 +618,7 @@ function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
onPointerDown={onPointerDown}
title={toggleLabel}
className={cn(
- "absolute inset-y-0 z-20 hidden w-4 touch-none cursor-ew-resize transition-[transform,background-color] ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2",
+ "absolute inset-y-0 z-20 hidden w-4 touch-none cursor-ew-resize transition-[translate,background-color] ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2",
"group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar",
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
diff --git a/packages/views/layout/panel-nav.tsx b/packages/views/layout/panel-nav.tsx
index e50e3da98e..3192b9843a 100644
--- a/packages/views/layout/panel-nav.tsx
+++ b/packages/views/layout/panel-nav.tsx
@@ -207,7 +207,7 @@ export function PanelSection({
<ChevronDown
aria-hidden
className={cn(
- "size-3.5 shrink-0 transition-[transform,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none",
+ "size-3.5 shrink-0 transition-[rotate,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none",
collapsed
? "-rotate-90"
: "opacity-0 group-hover/section:opacity-100 group-focus-within/section:opacity-100",
diff --git a/scripts/check-ui-transition-properties.mjs b/scripts/check-ui-transition-properties.mjs
new file mode 100644
index 0000000000..b32196841b
--- /dev/null
+++ b/scripts/check-ui-transition-properties.mjs
@@ -0,0 +1,188 @@
+#!/usr/bin/env node
+/**
+ * Catches hand-written `transition-[…]` lists that mix up `transform` and
+ * the standalone transform properties.
+ *
+ * In Tailwind v4, `translate-*`, `scale-*` and `rotate-*` write the standalone
+ * CSS `translate`, `scale` and `rotate` properties, not `transform`. A list
+ * such as `transition-[transform,opacity]` therefore snaps those utilities
+ * instead of animating them. The 3D `rotate-x/y/z-*` utilities are the
+ * reverse case: they still compose `transform`, so `transition-[rotate]`
+ * misses them. `transition` and `transition-transform` already include all
+ * four properties; only arbitrary lists can drift.
+ *
+ * Only that mix-up is reported. A list that names neither property, such as
+ * `transition-[width]` next to a static `-translate-x-1/2`, is left alone.
+ *
+ * Classes are grouped per string literal (a template literal's static text
+ * counts as one string), and the string arguments of one direct `cn()` or
+ * `clsx()` call — including ternary, `&&`/`||`/`??` and array branches — are
+ * grouped together. Classes passed through variables are not followed.
+ * apps/mobile is skipped: NativeWind runs Tailwind v3, where these utilities
+ * do go through `transform`.
+ *
+ * Run: node scripts/check-ui-transition-properties.mjs
+ */
+
+import { readdirSync, readFileSync, realpathSync } from "node:fs";
+import { extname, join, relative, resolve, sep } from "node:path";
+import { fileURLToPath } from "node:url";
+import ts from "typescript";
+
+const repoRoot = resolve(import.meta.dirname, "..");
+const roots = [
+ "apps/web",
+ "apps/desktop",
+ "apps/docs",
+ "apps/storybook",
+ "packages/ui",
+ "packages/views",
+ "packages/ee",
+];
+const extensions = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".mdx"]);
+const skippedDirectories = new Set(["node_modules", ".next", ".turbo", "dist", "build", "out"]);
+
+function walk(directory, files = []) {
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
+ if (entry.name.startsWith(".") || skippedDirectories.has(entry.name)) continue;
+ const path = join(directory, entry.name);
+ if (entry.isDirectory()) walk(path, files);
+ else if (extensions.has(extname(entry.name))) files.push(path);
+ }
+ return files;
+}
+
+function utilityName(token) {
+ const withoutVariant = token.slice(token.lastIndexOf(":") + 1);
+ return withoutVariant.replace(/^!/, "").replace(/!$/, "");
+}
+
+/** The CSS property a transform utility writes, or null for other classes. */
+function transformProperty(utility) {
+ const match = utility.match(/^-?(translate|scale|rotate)-(?:([xyz])-)?/);
+ if (!match) return null;
+ if (match[1] === "rotate" && match[2]) return "transform";
+ return match[1];
+}
+
+function isMismatch(listed, property) {
+ if (property === "transform") return listed.has("rotate") && !listed.has("transform");
+ return listed.has("transform") && !listed.has(property);
+}
+
+/** Checks class strings that land on one element; each finding keeps its source string. */
+export function classGroupViolations(strings) {
+ const listed = new Set();
+ const movers = [];
+
+ for (const string of strings) {
+ for (const token of string.text.split(/\s+/)) {
+ if (!token) continue;
+ const utility = utilityName(token);
+ const transition = utility.match(/^transition-\[([^\]]+)\]$/);
+ if (transition) {
+ for (const property of transition[1].split(",")) {
+ listed.add(property.replace(/_/g, " ").trim());
+ }
+ continue;
+ }
+ const property = transformProperty(utility);
+ if (property) movers.push({ string, token, property });
+ }
+ }
+
+ return movers.filter((mover) => isMismatch(listed, mover.property));
+}
+
+function classStrings(node) {
+ if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) return node.text;
+ if (ts.isTemplateExpression(node)) {
+ return [node.head.text, ...node.templateSpans.map((span) => span.literal.text)].join(" ");
+ }
+ return null;
+}
+
+const classMergers = new Set(["cn", "clsx"]);
+const branchOperators = new Set([
+ ts.SyntaxKind.AmpersandAmpersandToken,
+ ts.SyntaxKind.BarBarToken,
+ ts.SyntaxKind.QuestionQuestionToken,
+]);
+
+/** String nodes an argument of `cn()` can resolve to without following variables. */
+function mergedStringNodes(node, nodes = []) {
+ if (classStrings(node) !== null) nodes.push(node);
+ else if (ts.isParenthesizedExpression(node)) mergedStringNodes(node.expression, nodes);
+ else if (ts.isConditionalExpression(node)) {
+ mergedStringNodes(node.whenTrue, nodes);
+ mergedStringNodes(node.whenFalse, nodes);
+ } else if (ts.isBinaryExpression(node) && branchOperators.has(node.operatorToken.kind)) {
+ mergedStringNodes(node.left, nodes);
+ mergedStringNodes(node.right, nodes);
+ } else if (ts.isArrayLiteralExpression(node)) {
+ for (const element of node.elements) mergedStringNodes(element, nodes);
+ }
+ return nodes;
+}
+
+export function transitionViolations(sourceText, filePath) {
+ const source = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true);
+ const relativePath = relative(repoRoot, filePath).split(sep).join("/");
+ const violations = [];
+ const grouped = new Set();
+
+ const check = (nodes) => {
+ const strings = nodes.map((node) => ({ text: classStrings(node), node }));
+ for (const { string, token, property } of classGroupViolations(strings)) {
+ const { line, character } = source.getLineAndCharacterOfPosition(string.node.getStart(source));
+ violations.push({
+ file: relativePath,
+ line: line + 1,
+ column: character + 1,
+ token,
+ property,
+ });
+ }
+ };
+
+ const visit = (node) => {
+ if (
+ ts.isCallExpression(node) &&
+ ts.isIdentifier(node.expression) &&
+ classMergers.has(node.expression.text)
+ ) {
+ const nodes = node.arguments.flatMap((argument) => mergedStringNodes(argument));
+ for (const string of nodes) grouped.add(string);
+ check(nodes);
+ } else if (classStrings(node) !== null && !grouped.has(node)) {
+ check([node]);
+ }
+ ts.forEachChild(node, visit);
+ };
+ visit(source);
+ return violations;
+}
+
+function main() {
+ const files = roots.flatMap((root) => walk(join(repoRoot, root)));
+ const violations = files.flatMap((file) =>
+ transitionViolations(readFileSync(file, "utf8"), file),
+ );
+
+ if (violations.length > 0) {
+ console.error(`transition-[…] lists that confuse transform with translate/scale/rotate (${violations.length})`);
+ for (const violation of violations) {
+ console.error(
+ ` ${violation.file}:${violation.line}:${violation.column} ${violation.token} needs \`${violation.property}\``,
+ );
+ }
+ console.error(
+ "\nTailwind v4 `translate-*`, `scale-*` and `rotate-*` write the standalone `translate`, `scale` and `rotate` properties, while `rotate-x/y/z-*` compose `transform`. Name the property the class writes, e.g. `transition-[translate,opacity]`, or use `transition-transform`.",
+ );
+ process.exit(1);
+ }
+
+ console.log(`UI transition properties clean (${files.length} source files checked).`);
+}
+
+if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) main();
diff --git a/scripts/check-ui-transition-properties.test.mjs b/scripts/check-ui-transition-properties.test.mjs
new file mode 100644
index 0000000000..b0914d5dc0
--- /dev/null
+++ b/scripts/check-ui-transition-properties.test.mjs
@@ -0,0 +1,74 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { resolve } from "node:path";
+
+import {
+ classGroupViolations,
+ transitionViolations,
+} from "./check-ui-transition-properties.mjs";
+
+const probe = resolve("packages/views/zz-transition-probe.tsx");
+const tokens = (...texts) =>
+ classGroupViolations(texts.map((text) => ({ text }))).map((finding) => finding.token);
+const findings = (source) =>
+ transitionViolations(source, probe).map(({ line, token }) => `${line}:${token}`);
+
+test("rejects transform lists next to v4 translate, scale and rotate", () => {
+ assert.deepEqual(tokens("transition-[transform,width] translate-x-2"), ["translate-x-2"]);
+ assert.deepEqual(
+ tokens("transition-[opacity,transform] active:not-aria-[haspopup]:translate-y-px"),
+ ["active:not-aria-[haspopup]:translate-y-px"],
+ );
+ assert.deepEqual(
+ tokens("transition-[transform] ltr:-translate-x-1/2 hover:scale-[1.02] data-open:rotate-90"),
+ ["ltr:-translate-x-1/2", "hover:scale-[1.02]", "data-open:rotate-90"],
+ );
+ assert.deepEqual(tokens("transition-[transform,translate] scale-95"), ["scale-95"]);
+});
+
+test("rejects rotate lists next to 3D rotates, which still compose transform", () => {
+ assert.deepEqual(tokens("transition-[rotate] rotate-x-45"), ["rotate-x-45"]);
+ assert.deepEqual(tokens("transition-[transform] rotate-x-45"), []);
+});
+
+test("accepts matching lists, built-in transitions and static positioning", () => {
+ assert.deepEqual(tokens("transition-[translate,width] translate-x-2"), []);
+ assert.deepEqual(tokens("transition-transform rotate-90"), []);
+ assert.deepEqual(tokens("transition rotate-90 scale-95"), []);
+ assert.deepEqual(tokens("transition-[color,background-color,scale] active:scale-[0.96]"), []);
+ assert.deepEqual(tokens("transition-[width] group-data-[side=right]:rotate-180"), []);
+ assert.deepEqual(tokens("transition-[opacity] left-1/2 -translate-x-1/2"), []);
+});
+
+test("reads underscores in arbitrary lists as spaces", () => {
+ assert.deepEqual(tokens("transition-[transform,_translate] translate-x-2"), []);
+ assert.deepEqual(tokens("transition-[opacity,_transform] translate-x-2"), ["translate-x-2"]);
+});
+
+test("groups the string arguments of one cn() or clsx() call", () => {
+ assert.deepEqual(
+ findings(`
+ const chevron = cn(
+ "transition-[transform,opacity] duration-150",
+ collapsed
+ ? "-rotate-90"
+ : "opacity-0",
+ );
+ const tab = clsx(["transition-[transform,width]"], ready && \`translate-x-(--left) \${x}\`);
+ const fine = cn("transition-[translate,opacity]", open ?? "translate-y-1");
+ `),
+ ["5:-rotate-90", "8:translate-x-(--left)"],
+ );
+});
+
+test("does not follow classes passed through variables or other calls", () => {
+ assert.deepEqual(
+ findings(`
+ const jsx = <div className="transition-[transform] translate-y-1" />;
+ const template = \`transition-[transform] \${size} scale-95\`;
+ const moved = "translate-x-0";
+ const split = cn("transition-[transform]", moved, other("rotate-90"));
+ `),
+ ["2:translate-y-1", "3:scale-95"],
+ );
+});