fix(webui): show route-aligned skeletons from first paint (#6303)

This commit is contained in:
chengyongru authored and GitHub committed 2026-10-19 15:57:32 +08:00
1 parent af68da3280
commit 5d886fbb20
43 files changed
+1592 -213

No files matched your search

+10 -9
View File
@@ -369,15 +369,16 @@ describe("App layout", () => {
vi.unstubAllGlobals();
});
it("shows only layout shadows while bootstrap is pending", () => {
vi.mocked(fetchBootstrap).mockReturnValueOnce(new Promise(() => {}));
render(<App />);
expect(screen.getByRole("main")).toHaveAttribute("aria-busy", "true");
expect(screen.queryByRole("button")).not.toBeInTheDocument();
expect(screen.queryByRole("link")).not.toBeInTheDocument();
expect(screen.getByRole("status")).toHaveClass("startup-status");
expect(screen.queryByText("Loading nanobot…")).not.toBeInTheDocument();
});
it.each(["skills", "apps", "channels", "automations", "settings", "chat"]) (
"keeps the %s document skeleton while bootstrap is pending", (surface) => {
window.history.replaceState(null, "", `/#/${surface}`);
vi.mocked(fetchBootstrap).mockReturnValueOnce(new Promise(() => {}));
render(<App />);
expect(screen.getByRole("main")).toHaveAttribute("aria-busy", "true");
expect(screen.getByRole("main")).toHaveAttribute("data-startup-surface", surface);
expect(screen.getByRole("status")).toHaveTextContent("Loading nanobot…");
},
);
it.each([false, true])("enables task controls only when bootstrap advertises support: %s", async (supported) => {
mockSessions = [{
@@ -85,6 +85,20 @@ afterEach(() => {
});
describe("Automation task list and detail sheet", () => {
it("keeps the toolbar during initial loading and retains populated views during refresh", () => {
const view = render(<Harness payload={null} loading />);
expect(screen.getByRole("status", { name: "Loading automations..." })).toHaveAttribute("aria-busy", "true");
const toolbar = screen.getByRole("group", { name: "Task view" }).closest(".automation-panel-toolbar");
fireEvent.click(screen.getByRole("button", { name: /^Tasks$/ }));
expect(document.querySelectorAll("[data-automation-task-skeleton]")).toHaveLength(3);
view.rerender(<Harness loading />);
expect(screen.getByRole("button", { name: /PR watch/ })).toBeVisible();
expect(screen.queryByRole("status", { name: "Loading automations..." })).not.toBeInTheDocument();
expect(screen.getByRole("group", { name: "Task view" }).closest(".automation-panel-toolbar")).toBe(toolbar);
fireEvent.click(screen.getByRole("button", { name: /^Calendar$/ }));
expect(screen.getByRole("button", { name: /PR watch/ })).toBeVisible();
});
it("keeps view selection and filters in one persistent panel toolbar", () => {
render(<Harness />);
const views = screen.getByRole("group", { name: "Task view" });
+4 -1
View File
@@ -1,12 +1,14 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { Window } from "happy-dom";
import { renderToStaticMarkup } from "react-dom/server";
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
import { StartupSkeleton } from "@/components/StartupSkeleton";
import { MessageBubble } from "@/components/MessageBubble";
import { ContextCompactionNotice } from "@/components/thread/ContextCompactionNotice";
import { ThreadComposer } from "@/components/thread/ThreadComposer";
@@ -338,7 +340,8 @@ const ACCIDENTALLY_SPANISH_SETTINGS_KEYS = [
"settings.image.missingCredential",
"settings.oauth.signInHelp",
];
const INDEX_HTML = readFileSync(resolve(process.cwd(), "index.html"), "utf8");
const INDEX_HTML = readFileSync(resolve(process.cwd(), "index.html"), "utf8")
.replace("<!--startup-shell-->", renderToStaticMarkup(<StartupSkeleton />));
async function runPrebootLocale(storedLocale: string) {
const preboot = new Window({
url: "http://preboot.test",
@@ -168,7 +168,8 @@ describe("Linear member access", () => {
expect(requestMutation).toHaveBeenCalledTimes(1);
fireEvent.click(header());
expect(requestMutation).toHaveBeenCalledTimes(1);
expect(screen.getByText("Finding members…")).toBeVisible();
expect(screen.getByRole("status", { name: "Finding members…" })).toHaveAttribute("aria-busy", "true");
expect(document.querySelectorAll("[data-member-skeleton-row]")).toHaveLength(3);
expect(screen.getByRole("textbox", { name: "Search members" })).toBeEnabled();
expect(header()).toBeEnabled();
expect(document.querySelector(".animate-spin")).toBeNull();
@@ -86,6 +86,31 @@ describe("SessionInfoPopover", () => {
expect(screen.getByRole("button", { name: "Session details" })).toHaveFocus();
});
it("uses a skeleton for the initial request and keeps jobs while reopening and refreshing", async () => {
let finish!: (response: Response) => void;
vi.mocked(fetch).mockImplementationOnce(() => new Promise((resolve) => { finish = resolve; }));
const user = userEvent.setup();
const view = render(<SessionInfoPopover client={client} sessionKey="websocket:chat-1" token="tok" title="Release work" />);
await user.click(screen.getByRole("button", { name: "Session details" }));
expect(screen.getByRole("status", { name: "Loading automations..." })).toHaveAttribute("aria-busy", "true");
await act(async () => finish(automationsResponse([automationJob()])));
expect(await screen.findByRole("button", { name: /Morning check/ })).toBeVisible();
await user.keyboard("{Escape}");
let fail!: (error: Error) => void;
vi.mocked(fetch).mockImplementationOnce(() => new Promise((_, reject) => { fail = reject; }));
await user.click(screen.getByRole("button", { name: "Session details" }));
expect(screen.getByRole("button", { name: /Morning check/ })).toBeVisible();
expect(screen.queryByRole("status", { name: "Loading automations..." })).not.toBeInTheDocument();
await act(async () => fail(new Error("Refresh failed")));
expect(screen.getByRole("button", { name: /Morning check/ })).toBeVisible();
vi.mocked(fetch).mockImplementationOnce(() => new Promise((resolve) => { finish = resolve; }));
view.rerender(<SessionInfoPopover client={client} sessionKey="websocket:chat-2" token="tok" title="Other project" />);
expect(screen.queryByRole("button", { name: /Morning check/ })).not.toBeInTheDocument();
expect(screen.getByRole("status", { name: "Loading automations..." })).toBeVisible();
await act(async () => finish(automationsResponse([])));
expect(await screen.findByText("No automations in this session yet.")).toBeVisible();
});
it("manages a session task through the shared detail dialog", async () => {
const boundJob = { ...automationJob(), origin: {
session_key: "websocket:chat-1", channel: "websocket", chat_id: "chat-1",
+52
View File
@@ -164,6 +164,32 @@ describe("Settings system domains", () => {
},
);
it.each([
["skills", "Loading skills…"],
["apps", "Loading apps…"],
["channels", "Loading channels…"],
["automations", "Loading automations..."],
] as const)("keeps the %s loading surface mounted when the settings snapshot arrives", async (initialSection, label) => {
let resolveSettings!: (value: Response) => void;
const pendingSettings = new Promise<Response>((resolve) => { resolveSettings = resolve; });
vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => String(input) === "/api/settings"
? pendingSettings : new Promise<Response>(() => {})));
renderSettingsView({ initialSection, initialSettings: null, skillsLoading: true, showSidebar: false });
const skeleton = screen.getByRole("status", { name: label });
expect(skeleton).toHaveAttribute("aria-busy", "true");
await act(async () => { resolveSettings(jsonResponse(settingsPayload())); });
expect(screen.getByRole("status", { name: label })).toBe(skeleton);
});
it("shows available skills while the unrelated settings snapshot is still pending", () => {
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
renderSettingsView({ initialSection: "skills", initialSettings: null, showSidebar: false, skills: [{
name: "project-review", description: "Review a project.", source: "builtin", available: true, enabled: true,
}] });
expect(screen.getByRole("button", { name: "Open details for project-review" })).toBeVisible();
expect(screen.getByRole("textbox", { name: "Search installed skills" })).toBeVisible();
});
it("keeps the regular settings page at its existing width", () => {
renderSettingsView({ initialSection: "models", initialSettings: settingsPayload() });
@@ -258,6 +284,32 @@ describe("Settings system domains", () => {
},
);
it("loads only the skill detail body and preserves it while checking dependencies again", async () => {
const skill = { name: "pr-review", description: "Review pull requests", source: "builtin", available: false, enabled: true };
let finish!: (response: Response) => void;
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>((resolve) => { finish = resolve; })));
render(<ClientProvider client={{} as never} token="tok"><SkillsCatalogSettings skills={[skill]} /></ClientProvider>);
fireEvent.click(screen.getByRole("button", { name: "Open details for pr-review" }));
const detail = screen.getByRole("dialog");
expect(within(detail).getByText("Review pull requests")).toBeVisible();
expect(within(detail).getByRole("status", { name: "Loading skill details..." })).toHaveAttribute("aria-busy", "true");
await act(async () => finish(jsonResponse({ ...skill, raw_markdown: "Review repository changes.", requirements: {
bins: ["gh"], env: [], missing_bins: ["gh"], missing_env: [],
} })));
const toggle = within(detail).getByRole("switch");
expect(within(detail).getByText("Skill instructions")).toBeVisible();
let fail!: (error: Error) => void;
vi.mocked(fetch).mockImplementationOnce(() => new Promise((_, reject) => { fail = reject; }));
fireEvent.click(within(detail).getByRole("button", { name: "Check again" }));
expect(within(detail).getByText("Skill instructions")).toBeVisible();
expect(toggle).toBeDisabled();
expect(within(detail).queryByRole("status", { name: "Loading skill details..." })).not.toBeInTheDocument();
await act(async () => fail(new Error("Read failed")));
expect(within(detail).getByRole("alert")).toHaveTextContent("Could not load skill details.");
expect(within(detail).getByText("Skill instructions")).toBeVisible();
expect(toggle).toBeEnabled();
});
it("keeps skill group labels natural without changing grouping or filtering", () => {
render(<ClientProvider client={{} as never} token="tok">
<SkillsCatalogSettings skills={[
+5 -1
View File
@@ -140,7 +140,9 @@ export function renderSettingsView(
| "image"
| "browser"
| "runtime";
initialSettings?: SettingsPayload;
initialSettings?: SettingsPayload | null;
skills?: React.ComponentProps<typeof SettingsView>["skills"];
skillsLoading?: boolean;
showSidebar?: boolean;
mainNavigationExpanded?: boolean;
onBackToChat?: () => void;
@@ -163,6 +165,8 @@ export function renderSettingsView(
theme="light"
initialSection={options.initialSection ?? "apps"}
initialSettings={options.initialSettings}
skills={options.skills}
skillsLoading={options.skillsLoading}
showSidebar={options.showSidebar}
mainNavigationExpanded={options.mainNavigationExpanded}
onToggleTheme={() => {}}
+15
View File
@@ -74,6 +74,20 @@ function wrap(
}
describe("useSessions", () => {
it("distinguishes initial loading from revalidating a successfully loaded empty list", async () => {
let finish!: (rows: Awaited<ReturnType<typeof api.listSessions>>) => void;
vi.mocked(api.listSessions).mockImplementation(() => new Promise((resolve) => { finish = resolve; }));
const { result } = renderHook(() => useSessions(), { wrapper: wrap(fakeClient()) });
expect(result.current.initialLoading).toBe(true);
await act(async () => finish([]));
expect(result.current.initialLoading).toBe(false);
let refresh!: Promise<void>;
act(() => { refresh = result.current.refresh(); });
expect(result.current.loading).toBe(true);
expect(result.current.initialLoading).toBe(false);
await act(async () => { finish([]); await refresh; });
});
it("shows tab-cached sessions while revalidating and removes server-deleted rows", async () => {
activateReloadCache("ws://localhost:8765/");
writeReloadCache("sessions", [{
@@ -86,6 +100,7 @@ describe("useSessions", () => {
try {
expect(result.current.sessions[0]?.key).toBe("websocket:cached");
expect(result.current.loading).toBe(true);
expect(result.current.initialLoading).toBe(false);
await act(async () => finish([]));
expect(result.current.sessions).toEqual([]);
expect(result.current.loading).toBe(false);