fix(webui): synchronize neutral Ring sidebar activity indicators (#6371)

* fix(webui): synchronize neutral Trace sidebar activity indicators

* fix(webui): use the requested Ring activity indicator

* fix(webui): synchronize running rings before their first frame
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-21 21:40:39 +08:00
1 parent fbb61a373f
commit 29d1600837
7 files changed
+171 -3

No files matched your search

+2 -2
View File
@@ -176,10 +176,10 @@ OTHER DEALINGS IN THE FONT SOFTWARE.
--- ---
## loading.dev Blocks — history-loading animation (MIT) ## loading.dev Blocks and Ring — loading animations (MIT)
- **Source**: https://github.com/jakubkrehel/loading/tree/48ff9a1cd5f0446901ff1a8a3d5d5f906d3e36ff - **Source**: https://github.com/jakubkrehel/loading/tree/48ff9a1cd5f0446901ff1a8a3d5d5f906d3e36ff
- **Adapted**: the diagonal Blocks sweep in `webui/src/components/thread/ThreadHistoryStatus.tsx` and `webui/src/globals.css`. - **Adapted**: the diagonal Blocks sweep in `webui/src/components/thread/ThreadHistoryStatus.tsx` and `webui/src/globals.css`, and the circular Ring in `webui/src/components/ChatList.tsx` and `webui/src/globals.css`.
- **Bundled**: `nanobot/web/dist/assets/index-*.{js,css}` - **Bundled**: `nanobot/web/dist/assets/index-*.{js,css}`
``` ```
+3
View File
@@ -27,6 +27,7 @@ import { HistoryBoundaryFixture } from "./history-boundary-fixture";
import { ChatFailureFixture } from "./chat-failure-fixture"; import { ChatFailureFixture } from "./chat-failure-fixture";
import { ThreadLoadingFixture } from "./thread-loading-fixture"; import { ThreadLoadingFixture } from "./thread-loading-fixture";
import { AnswerOrderFixture } from "./answer-order-fixture"; import { AnswerOrderFixture } from "./answer-order-fixture";
import { SidebarActivityFixture } from "./sidebar-activity-fixture";
const history: UIMessage[] = [ const history: UIMessage[] = [
{ id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 }, { id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 },
@@ -169,6 +170,8 @@ await initializeI18n();
createRoot(document.getElementById("root")!).render(<TooltipProvider> createRoot(document.getElementById("root")!).render(<TooltipProvider>
{parameters.get("case") === "answer-order" {parameters.get("case") === "answer-order"
? <AnswerOrderFixture /> ? <AnswerOrderFixture />
: parameters.get("case") === "sidebar-activity"
? <SidebarActivityFixture />
: parameters.get("case") === "chat-failure" : parameters.get("case") === "chat-failure"
? <ChatFailureFixture parameters={parameters} /> ? <ChatFailureFixture parameters={parameters} />
: parameters.get("case") === "typography" : parameters.get("case") === "typography"
@@ -0,0 +1,36 @@
import { useState } from "react";
import { ChatList } from "@/components/ChatList";
import type { ChatSummary } from "@/lib/types";
const sessions: ChatSummary[] = ["Review history", "Locate messages", "Refine message bubbles", "Check MCP connection"].map((title, index) => ({
key: `websocket:activity-${index}`,
chatId: `activity-${index}`,
channel: "websocket",
title,
preview: "",
createdAt: "2026-10-21T10:00:00Z",
updatedAt: "2026-10-21T10:00:00Z",
handle: { id: `handle_activity_${index}`, name: ["bate", "jaru", "goyo", "tami"][index] },
}));
export function SidebarActivityFixture() {
const [count, setCount] = useState(new URLSearchParams(location.search).has("all") ? sessions.length : 1);
const [visible, setVisible] = useState(true);
const [activeKey, setActiveKey] = useState(sessions[0].key);
return <main className="flex min-h-screen flex-wrap items-start gap-6 bg-background p-4 text-foreground">
<section aria-label="Activity sidebar" className="h-[480px] w-80 max-w-full bg-sidebar">
{visible && <ChatList
sessions={sessions} activeKey={activeKey} onSelect={setActiveKey}
runningChatIds={sessions.slice(0, count).map((session) => session.chatId)}
sort="title_asc" onRequestDelete={() => {}} onTogglePin={() => {}}
onRequestRename={async () => {}} onToggleArchive={() => {}}
/>}
</section>
<div className="flex flex-col gap-3">
<button onClick={() => setCount((value) => Math.min(sessions.length, value + 1))}>Start next conversation</button>
<button onClick={() => setCount(1)}>Reset conversations</button>
<button onClick={() => setVisible((value) => !value)}>Toggle sidebar</button>
<button onClick={() => document.documentElement.classList.toggle("dark")}>Toggle theme</button>
</div>
</main>;
}
+94
View File
@@ -0,0 +1,94 @@
import { expect, test, type Page } from "@playwright/test";
async function samplePhases(page: Page) {
return page.getByRole("img", { name: "Agent running", exact: true }).evaluateAll((nodes) => nodes.map((node) => {
const animation = node.getAnimations({ subtree: true })[0];
const duration = animation.effect!.getTiming().duration as number;
return (Number(animation.currentTime) % duration) / duration;
}));
}
test("sidebar activity stays in phase across staggered starts, selection and remounts", async ({ page }) => {
await page.goto("/browser/fixture.html?case=sidebar-activity");
await expect(page.getByRole("img", { name: "Agent running", exact: true })).toHaveCount(1);
for (let count = 2; count <= 4; count++) {
// Stagger arrivals on the actual animation clock, rather than mounting every row together.
const previous = (await samplePhases(page))[0];
await expect.poll(async () => Math.abs((await samplePhases(page))[0] - previous)).toBeGreaterThan(0.15);
await page.getByRole("button", { name: "Start next conversation" }).click();
await expect(page.getByRole("img", { name: "Agent running", exact: true })).toHaveCount(count);
}
const samples = await page.evaluate(() => new Promise<number[][]>((resolve) => {
const result: number[][] = [];
const start = performance.now();
const sample = () => {
result.push(Array.from(document.querySelectorAll('[role="img"][aria-label="Agent running"]')).map((node) => {
const animation = node.getAnimations({ subtree: true })[0];
return (Number(animation.currentTime) % Number(animation.effect!.getTiming().duration)) / Number(animation.effect!.getTiming().duration);
}));
if (performance.now() - start < 1500) requestAnimationFrame(sample);
else resolve(result);
};
requestAnimationFrame(sample);
}));
expect(samples.length).toBeGreaterThan(10);
expect(new Set(samples.map((sample) => sample[0].toFixed(2))).size).toBeGreaterThan(10);
for (const phases of samples) expect(Math.max(...phases) - Math.min(...phases)).toBeLessThan(0.001);
await page.getByRole("button", { name: "@jaru Locate messages", exact: true }).click();
await page.getByRole("button", { name: "Toggle sidebar" }).click();
await expect(page.getByRole("img", { name: "Agent running", exact: true })).toHaveCount(0);
await page.getByRole("button", { name: "Toggle sidebar" }).click();
await expect(page.getByRole("img", { name: "Agent running", exact: true })).toHaveCount(4);
const phases = await samplePhases(page);
expect(Math.max(...phases) - Math.min(...phases)).toBeLessThan(0.001);
});
for (const width of [1280, 390]) {
test(`sidebar Ring follows the neutral theme at ${width}px and respects live motion preferences`, async ({ page }) => {
await page.setViewportSize({ width, height: 800 });
await page.goto("/browser/fixture.html?case=sidebar-activity&all");
const indicators = page.getByRole("img", { name: "Agent running", exact: true });
await expect(indicators).toHaveCount(4);
const colors: string[] = [];
for (const dark of [false, true]) {
await page.evaluate((enabled) => document.documentElement.classList.toggle("dark", enabled), dark);
const actual = await indicators.evaluateAll((nodes) => nodes.map((node) => {
const svg = node.querySelector("svg")!;
const reference = document.createElement("span");
reference.style.color = "hsl(var(--sidebar-muted-foreground))";
node.append(reference);
const expectedColor = getComputedStyle(reference).color;
reference.remove();
const rect = svg.getBoundingClientRect();
return { color: getComputedStyle(svg).color, expectedColor, size: [rect.width, rect.height] };
}));
for (const item of actual) {
expect(item.color).toBe(item.expectedColor);
expect(item.size).toEqual([12, 12]);
}
colors.push(actual[0].color);
await page.getByRole("button", { name: "@jaru Locate messages", exact: true }).hover();
await page.getByRole("button", { name: "@goyo Refine message bubbles", exact: true }).click();
expect(await indicators.evaluateAll((nodes) => nodes.map((node) => getComputedStyle(node.querySelector("svg")!).color)))
.toEqual(Array(4).fill(actual[0].color));
}
expect(colors[0]).not.toBe(colors[1]);
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
for (const reducedMotion of ["reduce", "no-preference"] as const) {
await page.emulateMedia({ reducedMotion });
await expect.poll(() => indicators.evaluateAll((nodes) => nodes.map((node) => node.getAnimations({ subtree: true }).length)))
.toEqual(Array(4).fill(reducedMotion === "reduce" ? 0 : 1));
if (reducedMotion === "no-preference") {
const phases = await samplePhases(page);
expect(Math.max(...phases) - Math.min(...phases)).toBeLessThan(0.001);
}
}
await page.emulateMedia({ reducedMotion: "reduce" });
await page.getByRole("button", { name: "Reset conversations" }).click();
await page.getByRole("button", { name: "Start next conversation" }).click();
await expect(indicators).toHaveCount(2);
expect(await indicators.evaluateAll((nodes) => nodes.map((node) => node.getAnimations({ subtree: true }).length))).toEqual([0, 0]);
});
}
+18 -1
View File
@@ -1884,6 +1884,12 @@ function ChatsFoldFooter({
); );
} }
function synchronizeRunningRing(element: SVGCircleElement | null) {
if (!element) return;
// Align pending animations before their first frame, not only after animationstart.
for (const animation of element.getAnimations()) animation.startTime = 0;
}
function SessionActivityIndicator({ function SessionActivityIndicator({
state, state,
}: { }: {
@@ -1917,7 +1923,18 @@ function SessionActivityIndicator({
aria-label={label} aria-label={label}
className="grid h-4 w-4 shrink-0 place-items-center" className="grid h-4 w-4 shrink-0 place-items-center"
> >
<span className="h-3 w-3 animate-spin rounded-full border border-blue-500/25 border-t-blue-500 [animation-duration:1.4s] motion-reduce:animate-none dark:border-blue-400/25 dark:border-t-blue-400" /> <svg
className="h-3 w-3 text-sidebar-muted-foreground"
viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" aria-hidden="true"
>
<circle cx="12" cy="12" r="10" opacity="0.2" />
<circle
cx="12" cy="12" r="10" strokeDasharray="16 46.8" strokeLinecap="round"
className="sidebar-running-ring"
ref={synchronizeRunningRing}
onAnimationStart={(event) => synchronizeRunningRing(event.currentTarget)}
/>
</svg>
</span> </span>
</HoverHint> </HoverHint>
); );
+14
View File
@@ -1092,6 +1092,20 @@
} }
} }
/* loading.dev Ring, Copyright (c) 2026 Jakub Krehel (MIT); THIRD_PARTY_NOTICES.md. */
.sidebar-running-ring {
transform-origin: center;
animation: sidebar-running-ring 800ms linear infinite;
}
@keyframes sidebar-running-ring {
to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
.sidebar-running-ring {
animation: none;
}
}
@media (pointer: coarse) { @media (pointer: coarse) {
/* Readable form text avoids Safari's focus zoom without disabling the user's /* Readable form text avoids Safari's focus zoom without disabling the user's
pinch zoom. Keep this after utilities so compact desktop overrides cannot pinch zoom. Keep this after utilities so compact desktop overrides cannot
+4
View File
@@ -12,6 +12,10 @@ if (!HTMLElement.prototype.hasPointerCapture) {
if (!HTMLElement.prototype.scrollIntoView) { if (!HTMLElement.prototype.scrollIntoView) {
HTMLElement.prototype.scrollIntoView = () => {}; HTMLElement.prototype.scrollIntoView = () => {};
} }
// happy-dom has no animation timeline; rendered motion is covered in browser tests.
if (!Element.prototype.getAnimations) {
Element.prototype.getAnimations = () => [];
}
// happy-dom does not load fonts; text measurements can run immediately. // happy-dom does not load fonts; text measurements can run immediately.
Object.defineProperty(document, "fonts", { Object.defineProperty(document, "fonts", {