From 29d1600837d07c54aae3eabfbfac38739e3c508d Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Wed, 21 Oct 2026 21:40:39 +0800 Subject: [PATCH] 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 --- THIRD_PARTY_NOTICES.md | 4 +- webui/browser/fixture.tsx | 3 + webui/browser/sidebar-activity-fixture.tsx | 36 +++++++++ webui/browser/sidebar-activity.spec.ts | 94 ++++++++++++++++++++++ webui/src/components/ChatList.tsx | 19 ++++- webui/src/globals.css | 14 ++++ webui/src/tests/setup.ts | 4 + 7 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 webui/browser/sidebar-activity-fixture.tsx create mode 100644 webui/browser/sidebar-activity.spec.ts diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index e92b666f5..deac0d172 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -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 -- **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}` ``` diff --git a/webui/browser/fixture.tsx b/webui/browser/fixture.tsx index 37848094c..f1e8cdbec 100644 --- a/webui/browser/fixture.tsx +++ b/webui/browser/fixture.tsx @@ -27,6 +27,7 @@ import { HistoryBoundaryFixture } from "./history-boundary-fixture"; import { ChatFailureFixture } from "./chat-failure-fixture"; import { ThreadLoadingFixture } from "./thread-loading-fixture"; import { AnswerOrderFixture } from "./answer-order-fixture"; +import { SidebarActivityFixture } from "./sidebar-activity-fixture"; const history: UIMessage[] = [ { id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 }, @@ -169,6 +170,8 @@ await initializeI18n(); createRoot(document.getElementById("root")!).render( {parameters.get("case") === "answer-order" ? + : parameters.get("case") === "sidebar-activity" + ? : parameters.get("case") === "chat-failure" ? : parameters.get("case") === "typography" diff --git a/webui/browser/sidebar-activity-fixture.tsx b/webui/browser/sidebar-activity-fixture.tsx new file mode 100644 index 000000000..d9355b713 --- /dev/null +++ b/webui/browser/sidebar-activity-fixture.tsx @@ -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
+
+ {visible && session.chatId)} + sort="title_asc" onRequestDelete={() => {}} onTogglePin={() => {}} + onRequestRename={async () => {}} onToggleArchive={() => {}} + />} +
+
+ + + + +
+
; +} diff --git a/webui/browser/sidebar-activity.spec.ts b/webui/browser/sidebar-activity.spec.ts new file mode 100644 index 000000000..19628e9ab --- /dev/null +++ b/webui/browser/sidebar-activity.spec.ts @@ -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((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]); + }); +} diff --git a/webui/src/components/ChatList.tsx b/webui/src/components/ChatList.tsx index bcf9541f8..62b7aa28e 100644 --- a/webui/src/components/ChatList.tsx +++ b/webui/src/components/ChatList.tsx @@ -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({ state, }: { @@ -1917,7 +1923,18 @@ function SessionActivityIndicator({ aria-label={label} className="grid h-4 w-4 shrink-0 place-items-center" > - + ); diff --git a/webui/src/globals.css b/webui/src/globals.css index db905ebfd..1adeba295 100644 --- a/webui/src/globals.css +++ b/webui/src/globals.css @@ -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) { /* Readable form text avoids Safari's focus zoom without disabling the user's pinch zoom. Keep this after utilities so compact desktop overrides cannot diff --git a/webui/src/tests/setup.ts b/webui/src/tests/setup.ts index 96ef96868..0344d303c 100644 --- a/webui/src/tests/setup.ts +++ b/webui/src/tests/setup.ts @@ -12,6 +12,10 @@ if (!HTMLElement.prototype.hasPointerCapture) { if (!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. Object.defineProperty(document, "fonts", {