Skip to content

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

Go

fix(ui): reduce text shimmer repainting (MUL-7466) (#8653)

Multica Eve8bafd36ba87d
diff --git a/e2e/shimmer-text.spec.ts b/e2e/shimmer-text.spec.ts
new file mode 100644
index 0000000000..73dc141ea5
--- /dev/null
+++ b/e2e/shimmer-text.spec.ts
@@ -0,0 +1,106 @@
+import { readFileSync } from "node:fs";
+import { expect, test, type Page } from "@playwright/test";
+import { shimmerTextScript } from "../packages/ui/test/shimmer-text-bundle.mjs";
+
+// No server required. Use the production markup/styles: jsdom cannot check
+// counter-translated glyph alignment, text selection, or media fallbacks.
+const css = readFileSync("packages/ui/styles/base.css", "utf8");
+
+declare global {
+ interface Window {
+ shimmerFixture: { render(text: string, active: boolean): void };
+ }
+}
+
+test.beforeEach(async ({ page }) => {
+ await page.setContent(`<style>
+ :root { --muted-foreground: #666; --foreground: #111; }
+ ${css}
+ </style><div id="mount"></div>`);
+ await page.addScriptTag({ content: shimmerTextScript });
+});
+
+async function renderLabel(page: Page, text = "Working", active = true) {
+ await page.evaluate(({ text, active }) => window.shimmerFixture.render(text, active), { text, active });
+}
+
+test("exposes and copies the label once, including localized and updated counts", async ({ page }) => {
+ for (const text of ["Working", "2 agents working", "12 个智能体正在工作"]) {
+ await renderLabel(page, text);
+ expect(await page.evaluate(() => document.getAnimations().filter((a) => a.playState === "running").length)).toBe(2);
+ expect(await page.locator("#fixture").ariaSnapshot()).toBe(`- text: ${text}`);
+ const selected = await page.locator("#label").evaluate((label) => {
+ const range = document.createRange();
+ range.selectNodeContents(label);
+ const selection = window.getSelection()!;
+ selection.removeAllRanges();
+ selection.addRange(range);
+ return selection.toString();
+ });
+ expect(selected).toBe(text);
+ }
+});
+
+test("keeps both copies aligned throughout the sweep and truncates long labels", async ({ page }) => {
+ for (const text of ["Working", "12 个智能体正在工作", "Searching through a very long project name"]) {
+ await renderLabel(page, text);
+ // Include both sides of the repeating sweep's seam.
+ for (const time of [0, 400, 1250, 2499, 2501]) {
+ const geometry = await page.evaluate((time) => {
+ for (const animation of document.getAnimations()) {
+ animation.pause();
+ animation.currentTime = time;
+ }
+ const label = document.querySelector<HTMLElement>("#label")!;
+ const copy = label.querySelector<HTMLElement>(".shimmer-text-copy")!;
+ const baseRect = label.getBoundingClientRect();
+ const copyRect = copy.getBoundingClientRect();
+ return {
+ dx: Math.abs(baseRect.x - copyRect.x),
+ dy: Math.abs(baseRect.y - copyRect.y),
+ dw: Math.abs(baseRect.width - copyRect.width),
+ width: baseRect.width,
+ overflow: getComputedStyle(label).textOverflow,
+ copyOverflow: getComputedStyle(copy).textOverflow,
+ clipped: label.scrollWidth > label.clientWidth,
+ };
+ }, time);
+ expect(geometry.dx).toBeLessThan(0.1);
+ expect(geometry.dy).toBeLessThan(0.1);
+ expect(geometry.dw).toBeLessThan(0.1);
+ expect(geometry.width).toBeLessThanOrEqual(180);
+ expect(geometry.overflow).toBe("ellipsis");
+ expect(geometry.copyOverflow).toBe("ellipsis");
+ if (text.startsWith("Searching")) expect(geometry.clipped).toBe(true);
+ }
+ }
+});
+
+test("remains readable without running animations when inactive or motion is reduced", async ({ page }) => {
+ await renderLabel(page, "Queued", false);
+ await expect(page.locator("#label")).toHaveText("Queued");
+ expect(await page.evaluate(() => document.getAnimations().length)).toBe(0);
+
+ await page.emulateMedia({ reducedMotion: "reduce" });
+ await renderLabel(page);
+ await expect(page.locator("#label")).toHaveCSS("color", "rgb(102, 102, 102)");
+ await expect(page.locator(".shimmer-text-window")).toBeHidden();
+ expect(await page.evaluate(() => document.getAnimations().length)).toBe(0);
+});
+
+test("uses readable system text and no highlight in forced colors", async ({ page }) => {
+ await page.emulateMedia({ forcedColors: "active" });
+ await renderLabel(page);
+ await expect(page.locator(".shimmer-text-window")).toBeHidden();
+ expect(await page.evaluate(() => document.getAnimations().length)).toBe(0);
+ expect(await page.locator("#fixture").ariaSnapshot()).toBe("- text: Working");
+ const colors = await page.locator("#label").evaluate((label) => {
+ const probe = document.createElement("span");
+ probe.style.color = "CanvasText";
+ document.body.append(probe);
+ const result = [getComputedStyle(label).color, getComputedStyle(probe).color];
+ probe.remove();
+ return result;
+ });
+ expect(colors[0]).toBe(colors[1]);
+});
diff --git a/packages/ui/components/common/shimmer-text.tsx b/packages/ui/components/common/shimmer-text.tsx
new file mode 100644
index 0000000000..53b4861f4d
--- /dev/null
+++ b/packages/ui/components/common/shimmer-text.tsx
@@ -0,0 +1,26 @@
+import type { ComponentProps } from "react";
+import { cn } from "@multica/ui/lib/utils";
+
+interface ShimmerTextProps extends Omit<ComponentProps<"span">, "children"> {
+ children: string;
+ active?: boolean;
+}
+
+/** A single-line activity label. Only the decorative highlight moves. */
+export function ShimmerText({
+ children,
+ active = true,
+ className,
+ ...props
+}: ShimmerTextProps) {
+ return (
+ <span className={cn(active && "shimmer-text", className)} {...props}>
+ {children}
+ {active && (
+ <span className="shimmer-text-window" aria-hidden="true">
+ <span className="shimmer-text-copy">{children}</span>
+ </span>
+ )}
+ </span>
+ );
+}
diff --git a/packages/ui/package.json b/packages/ui/package.json
index d56e2d4837..4a4880036b 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -72,6 +72,7 @@
"@types/linkify-it": "^5.0.0",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
+ "esbuild": "^0.25.12",
"typescript": "catalog:"
}
}
diff --git a/packages/ui/styles/base.css b/packages/ui/styles/base.css
index 11030983cc..97acf4bea2 100644
--- a/packages/ui/styles/base.css
+++ b/packages/ui/styles/base.css
@@ -132,35 +132,57 @@
animation: chat-impulse 1.6s ease-in-out infinite;
}
-/* ChatGPT-style "thinking" shimmer for inline text — a soft light sweep
- * runs across the glyphs, signalling "the agent is doing something" without
- * a separate spinner. Pure CSS: linear-gradient clipped to the text shape,
- * the gradient slid across via background-position. Uses the same muted →
- * foreground tokens chat copy normally uses, so the effect adapts to light
- * and dark mode without per-mode overrides.
- *
- * Apply to a <span> wrapping the label only — not the whole pill, since
- * the timer counter and Cancel button shouldn't shimmer. */
-@keyframes chat-text-shimmer {
- 0% { background-position: 200% 0; }
- 100% { background-position: -200% 0; }
-}
-
-.animate-chat-text-shimmer {
- background-image: linear-gradient(
- 90deg,
- var(--muted-foreground) 0%,
- var(--muted-foreground) 35%,
- var(--foreground) 50%,
- var(--muted-foreground) 65%,
- var(--muted-foreground) 100%
- );
- background-size: 200% 100%;
- background-clip: text;
- -webkit-background-clip: text;
- color: transparent;
- -webkit-text-fill-color: transparent;
- animation: chat-text-shimmer 2.5s linear infinite;
+/* ShimmerText keeps the base glyphs still and moves a masked highlight over
+ * them. Counter-translate the copy so only the light moves, avoiding the
+ * per-frame text repaint caused by animating a clipped background-position.
+ * The old 200%-wide gradient travelled four label widths per 2.5s cycle.
+ * A six-width window with a repeating two-width mask preserves that spacing
+ * and covers the label throughout the sweep, including the loop seam. */
+@keyframes shimmer-text-window {
+ from { transform: translateX(-66.6666666667%); }
+ to { transform: translateX(0%); }
+}
+
+@keyframes shimmer-text-copy {
+ from { transform: translateX(400%); }
+ to { transform: translateX(0%); }
+}
+
+.shimmer-text {
+ display: inline-block;
+ position: relative;
+ max-width: 100%;
+ overflow: hidden;
+ vertical-align: bottom;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ color: var(--muted-foreground);
+}
+
+.shimmer-text-window {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 600%;
+ height: 100%;
+ pointer-events: none;
+ user-select: none;
+ mask-image: linear-gradient(90deg, transparent 35%, black 50%, transparent 65%);
+ mask-size: calc(100% / 3) 100%;
+ mask-repeat: repeat-x;
+ animation: shimmer-text-window 2.5s linear infinite;
+}
+
+.shimmer-text-copy {
+ display: block;
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: calc(100% / 6);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ color: var(--foreground);
+ animation: shimmer-text-copy 2.5s linear infinite;
}
/* Navigation progress bar: 2px brand-colored indeterminate sweep with a
@@ -313,15 +335,14 @@ html[data-dnd-dragging="true"] * {
.animate-completion-badge,
.animate-completion-check,
.animate-chat-impulse,
- .animate-chat-text-shimmer,
+ .shimmer-text-window,
+ .shimmer-text-copy,
.animate-nav-progress-sweep {
animation: none;
}
- .animate-chat-text-shimmer {
- background-image: none;
- color: var(--muted-foreground);
- -webkit-text-fill-color: currentColor;
+ .shimmer-text-window {
+ display: none;
}
[data-comment-actions],
@@ -331,11 +352,17 @@ html[data-dnd-dragging="true"] * {
}
@media (forced-colors: active) {
- .animate-chat-text-shimmer {
- animation: none;
- background-image: none;
+ .shimmer-text {
color: CanvasText;
- -webkit-text-fill-color: currentColor;
+ }
+
+ .shimmer-text-window,
+ .shimmer-text-copy {
+ animation: none;
+ }
+
+ .shimmer-text-window {
+ display: none;
}
}
diff --git a/packages/ui/test/shimmer-text-bundle.mjs b/packages/ui/test/shimmer-text-bundle.mjs
new file mode 100644
index 0000000000..86a1a2c06b
--- /dev/null
+++ b/packages/ui/test/shimmer-text-bundle.mjs
@@ -0,0 +1,13 @@
+import { buildSync } from "esbuild";
+import { fileURLToPath, URL } from "node:url";
+
+// Playwright's JSX transform makes component descriptors, not React elements.
+// Bundle the fixture with the same React JSX runtime as the consuming apps.
+export const shimmerTextScript = buildSync({
+ entryPoints: [fileURLToPath(new URL("./shimmer-text-fixture.tsx", import.meta.url))],
+ bundle: true,
+ write: false,
+ format: "iife",
+ globalName: "shimmerFixture",
+ define: { "process.env.NODE_ENV": '"production"' },
+}).outputFiles[0].text;
diff --git a/packages/ui/test/shimmer-text-fixture.tsx b/packages/ui/test/shimmer-text-fixture.tsx
new file mode 100644
index 0000000000..cee8f07554
--- /dev/null
+++ b/packages/ui/test/shimmer-text-fixture.tsx
@@ -0,0 +1,18 @@
+import { flushSync } from "react-dom";
+import { createRoot } from "react-dom/client";
+import { ShimmerText } from "../components/common/shimmer-text";
+
+const root = createRoot(document.getElementById("mount")!);
+
+// Mount the real component for browser-only layout and accessibility checks.
+export function render(text: string, active = true) {
+ flushSync(() =>
+ root.render(
+ <div id="fixture" style={{ width: 180, font: "15px/22px sans-serif" }}>
+ <ShimmerText id="label" active={active}>
+ {text}
+ </ShimmerText>
+ </div>,
+ ),
+ );
+}
diff --git a/packages/views/chat/components/task-status-pill.tsx b/packages/views/chat/components/task-status-pill.tsx
index fe32a9a625..159a35b299 100644
--- a/packages/views/chat/components/task-status-pill.tsx
+++ b/packages/views/chat/components/task-status-pill.tsx
@@ -1,7 +1,7 @@
"use client";
import { useEffect, useRef, useState } from "react";
-import { cn } from "@multica/ui/lib/utils";
+import { ShimmerText } from "@multica/ui/components/common/shimmer-text";
import { UnicodeSpinner } from "@multica/ui/components/common/unicode-spinner";
import type { AgentAvailability } from "@multica/core/agents";
import type { ChatPendingTask, TaskMessagePayload } from "@multica/core/types";
@@ -216,9 +216,9 @@ export function TaskStatusPill({
<UnicodeSpinner name="breathe" className="opacity-70" />
)}
<span className="truncate">
- <span className={cn(!stage.static && "animate-chat-text-shimmer")}>
+ <ShimmerText active={!stage.static}>
{stage.label}
- </span>
+ </ShimmerText>
<span className="opacity-70 tabular-nums"> · {formatElapsedSecs(elapsedSecs)}</span>
</span>
</div>
diff --git a/packages/views/issues/components/inline-comment-run.test.tsx b/packages/views/issues/components/inline-comment-run.test.tsx
index 6b794fdf59..471d6337b9 100644
--- a/packages/views/issues/components/inline-comment-run.test.tsx
+++ b/packages/views/issues/components/inline-comment-run.test.tsx
@@ -233,7 +233,7 @@ describe("InlineCommentRun", () => {
const { client, rerender } = setup(current);
await screen.findByText("pnpm test");
const progress = screen.getByText("pnpm test");
- expect(progress).not.toHaveClass("animate-chat-text-shimmer");
+ expect(progress).not.toHaveClass("shimmer-text");
expect(progress.closest("[data-run-summary]")).toHaveClass("h-[1lh]", "overflow-hidden");
expect(document.querySelector("[data-run-loading-indicator]")).toHaveClass(
"motion-safe:animate-spin",
diff --git a/packages/views/issues/components/issue-agent-activity-indicator.test.tsx b/packages/views/issues/components/issue-agent-activity-indicator.test.tsx
index e98d361ae9..7c24e2dd70 100644
--- a/packages/views/issues/components/issue-agent-activity-indicator.test.tsx
+++ b/packages/views/issues/components/issue-agent-activity-indicator.test.tsx
@@ -147,7 +147,7 @@ describe("IssueAgentActivityIndicator", () => {
expect(screen.queryByTestId("hover-card-trigger")).toBeNull();
// The cue itself survives — only the popup behind it is dropped.
expect(screen.getByTestId("agent-avatar-stack")).not.toBeNull();
- expect(screen.getByText("Working")).not.toBeNull();
+ expect(screen.getByText("Working", { ignore: '[aria-hidden="true"] *' })).not.toBeNull();
});
it("renders nothing when no agent is on the issue", () => {
@@ -188,7 +188,7 @@ it("prioritizes active runs, marking wakeup origin separately from future count"
];
mockState.summaries = [eventSummary];
render(<IssueAgentActivityIndicator issueId="issue-1" hoverCard={false} />);
- expect(screen.getByText("Working")).toBeInTheDocument();
+ expect(screen.getByText("Working", { ignore: '[aria-hidden="true"] *' })).toBeInTheDocument();
expect(screen.getByLabelText("Triggered by wakeup")).toBeInTheDocument();
expect(screen.getByText("+2")).toBeInTheDocument();
expect(screen.queryByText("Waiting for trigger")).toBeNull();
diff --git a/packages/views/issues/components/issue-agent-activity-indicator.tsx b/packages/views/issues/components/issue-agent-activity-indicator.tsx
index d9ac7e7fc8..b0f8523f0b 100644
--- a/packages/views/issues/components/issue-agent-activity-indicator.tsx
+++ b/packages/views/issues/components/issue-agent-activity-indicator.tsx
@@ -3,6 +3,7 @@
import { memo, useCallback, useMemo, useState } from "react";
import { Bell, Clock3 } from "lucide-react";
import { useQuery } from "@tanstack/react-query";
+import { ShimmerText } from "@multica/ui/components/common/shimmer-text";
import {
HoverCard,
HoverCardTrigger,
@@ -62,9 +63,8 @@ interface IssueAgentActivityIndicatorProps {
* - future wakeups only → next time/event + remaining count
* - no tasks or wakeups → return null (no chrome, no placeholder)
*
- * The shimmer reuses chat's `animate-chat-text-shimmer` utility (defined
- * in packages/ui/styles/base.css). Earlier iterations layered a brand
- * ring + opacity pulse around the avatars; both read as nervous on a
+ * The shimmer shares chat's ShimmerText component. Earlier iterations layered
+ * a brand ring + opacity pulse around the avatars; both read as nervous on a
* dense board. Moving the "alive" signal onto the label keeps the
* avatars themselves still and lets the cue ride a piece of text the
* user can already read.
@@ -159,19 +159,14 @@ export const IssueAgentActivityIndicator = memo(
opacity={opacity}
max={3}
/>
- {/* No leading-none: the shimmer paints glyphs via background-clip:
- text, and the background only covers the line box — a squeezed
- line box leaves descenders transparent. */}
- <span
- className={cn(
- "text-micro",
- isRunning ? "animate-chat-text-shimmer" : "text-muted-foreground",
- )}
+ <ShimmerText
+ active={isRunning}
+ className="text-micro text-muted-foreground"
>
{isRunning
? t(($) => $.agent_activity.status_running)
: t(($) => $.agent_activity.status_queued)}
- </span>
+ </ShimmerText>
{wakeupTriggered && (
<Bell
className="size-3 text-muted-foreground"
diff --git a/packages/views/issues/components/sub-issues-agent-working-chip.test.tsx b/packages/views/issues/components/sub-issues-agent-working-chip.test.tsx
index ff3ddd7afb..922451e4ab 100644
--- a/packages/views/issues/components/sub-issues-agent-working-chip.test.tsx
+++ b/packages/views/issues/components/sub-issues-agent-working-chip.test.tsx
@@ -118,7 +118,7 @@ describe("SubIssuesAgentWorkingChip", () => {
render(<SubIssuesAgentWorkingChip parentIssueId="parent-1" />);
expect(
- screen.getByText("agent_activity.chip_agents_working:2"),
+ screen.getByText("agent_activity.chip_agents_working:2", { ignore: '[aria-hidden="true"] *' }),
).not.toBeNull();
expect(screen.getByTestId("agent-avatar-stack").textContent).toBe(
"agent-1,agent-2",
@@ -137,7 +137,7 @@ describe("SubIssuesAgentWorkingChip", () => {
// The number and the hover body must never disagree — they are the same
// list, not two derivations of one snapshot.
expect(
- screen.getByText("agent_activity.chip_agents_working:3"),
+ screen.getByText("agent_activity.chip_agents_working:3", { ignore: '[aria-hidden="true"] *' }),
).not.toBeNull();
expect(screen.getByTestId("hover-body").textContent).toBe("3");
});
diff --git a/packages/views/issues/components/sub-issues-agent-working-chip.tsx b/packages/views/issues/components/sub-issues-agent-working-chip.tsx
index 2385bc7212..4b86a1d847 100644
--- a/packages/views/issues/components/sub-issues-agent-working-chip.tsx
+++ b/packages/views/issues/components/sub-issues-agent-working-chip.tsx
@@ -2,6 +2,7 @@
import { memo } from "react";
import { useQuery } from "@tanstack/react-query";
+import { ShimmerText } from "@multica/ui/components/common/shimmer-text";
import {
HoverCard,
HoverCardTrigger,
@@ -58,14 +59,11 @@ export const SubIssuesAgentWorkingChip = memo(
}
>
<AgentAvatarStack agentIds={agentIds} size="xs" max={3} />
- {/* No leading-none: the shimmer paints glyphs via background-clip:
- text, and the background only covers the line box — a squeezed
- line box leaves descenders transparent. */}
- <span className="animate-chat-text-shimmer text-micro font-medium tabular-nums">
+ <ShimmerText className="text-micro font-medium tabular-nums">
{t(($) => $.agent_activity.chip_agents_working, {
count: agentIds.length,
})}
- </span>
+ </ShimmerText>
</HoverCardTrigger>
<HoverCardContent align="start" className="w-72">
<WorkingAgentsHoverContent agents={agents} />
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 77bf231db1..e00b009dd9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -915,6 +915,9 @@ importers:
'@types/react-dom':
specifier: ^19.2.0
version: 19.2.3(@types/[email protected])
+ esbuild:
+ specifier: ^0.25.12
+ version: 0.25.12
typescript:
specifier: 'catalog:'
version: 5.9.3