AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
perf(frontend/copilot): select UI store fields and resize once per frame (#15709)
Abhimanyu Yadav49ab37bfc6a6
diff --git a/autogpt_platform/frontend/scripts/perf/scenarios/copilot-resize-drag.ts b/autogpt_platform/frontend/scripts/perf/scenarios/copilot-resize-drag.tsnew file mode 100644index 0000000000..cf4a020fb0--- /dev/null+++ b/autogpt_platform/frontend/scripts/perf/scenarios/copilot-resize-drag.ts@@ -0,0 +1,42 @@+import { openLongSession } from "../lib/copilot-page";+import { settle, type Scenario } from "../lib/scenario";++const MOVES = 60;+const DRAG_MS = 1_000;+// 60 moves of 2 px widen the 432 px default panel to 552 px, under the 600 px+// cap, so every move asks for a new width.+const STEP_PX = 2;+const READY_TIMEOUT_MS = 30_000;++export const copilotResizeDrag: Scenario = {+ name: "copilot-resize-drag",+ description:+ "Open the files panel of a 200-message chat and drag its resize handle 120 px wider over 1 s (60 pointer moves).",+ readyWhen:+ "the newest user message and the composer are visible, the files panel is open, then network idle + 1 s",+ windowMs: 1_000,+ async setup(ctx) {+ const { page } = ctx;+ await openLongSession({ ctx });+ await page.getByRole("button", { name: /^Open files/ }).click();+ const handle = page.locator("[data-context-panel] [role='separator']");+ await handle.waitFor({ state: "visible", timeout: READY_TIMEOUT_MS });+ await settle(page);+ const box = await handle.boundingBox();+ if (!box)+ throw new Error("Context panel resize handle has no bounding box");+ return {+ async run() {+ const x = box.x + box.width / 2;+ const y = box.y + box.height / 2;+ await page.mouse.move(x, y);+ await page.mouse.down();+ for (let move = 1; move <= MOVES; move++) {+ await page.mouse.move(x - move * STEP_PX, y);+ await page.waitForTimeout(DRAG_MS / MOVES);+ }+ await page.mouse.up();+ },+ };+ },+};diff --git a/autogpt_platform/frontend/scripts/perf/scenarios/registry.ts b/autogpt_platform/frontend/scripts/perf/scenarios/registry.tsindex 7979d1637c..6c92b53281 100644--- a/autogpt_platform/frontend/scripts/perf/scenarios/registry.ts+++ b/autogpt_platform/frontend/scripts/perf/scenarios/registry.ts@@ -4,6 +4,7 @@ import { builderDragRunning } from "./builder-drag-running";import { builderRunEvents } from "./builder-run-events";import { copilotBackgroundStream } from "./copilot-background-stream";import { copilotIdle } from "./copilot-idle";+import { copilotResizeDrag } from "./copilot-resize-drag";import { copilotStreamCode } from "./copilot-stream-code";import { copilotStreamReply } from "./copilot-stream-reply";import { copilotSwitchThreads } from "./copilot-switch-threads";@@ -25,6 +26,7 @@ export const SCENARIOS: Scenario[] = [libraryRunningEvents,builderRunEvents,copilotToolWait,+ copilotResizeDrag,];export function findScenario(name: string) {diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store-selectors.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store-selectors.test.tsxnew file mode 100644index 0000000000..54ce5e5ea8--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store-selectors.test.tsx@@ -0,0 +1,199 @@+import { getGetV2ListChatConnectionsMockHandler200 } from "@/app/api/__generated__/endpoints/chat/chat.msw";+import { server } from "@/mocks/mock-server";+import {+ act,+ render,+ renderHook,+ waitFor,+} from "@/tests/integrations/test-utils";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { NuqsTestingAdapter } from "nuqs/adapters/testing";+import { Profiler, useState, type ReactNode } from "react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { useChatInput } from "../components/ChatInput/useChatInput";+import { useConnectionPicker } from "../components/ChatInput/components/ConnectionPicker/useConnectionPicker";+import { useLockedTierFallback } from "../components/ChatInput/components/ConnectionPicker/useLockedTierFallback";+import { NotificationToggle } from "../components/ChatSidebar/components/NotificationToggle/NotificationToggle";+import { NotificationDialog } from "../components/NotificationDialog/NotificationDialog";+import { DEFAULT_PANEL_WIDTH, useCopilotUIStore } from "../store";+import { useSessionDeletion } from "../useSessionDeletion";+import { useWorkflowImportAutoSubmit } from "../useWorkflowImportAutoSubmit";++// Each copilot UI store reader subscribes to the fields it reads, not the+// whole store: a write to a field it does not read (a panel resize writes+// `contextPanelWidth` every frame of a drag) leaves it alone, while a write+// to a field it does read still reaches it.++vi.mock("@/lib/auth/hooks/useAuth", () => ({+ useAuth: () => ({ user: { id: "user-1" }, isLoggedIn: true }),+}));++function writeUnrelatedField() {+ act(() => {+ useCopilotUIStore+ .getState()+ .setContextPanelWidth(useCopilotUIStore.getState().contextPanelWidth + 7);+ });+}++async function settle() {+ await act(async () => {});+}++function HookProviders({ children }: { children: ReactNode }) {+ const [queryClient] = useState(+ () =>+ new QueryClient({+ defaultOptions: { queries: { retry: false } },+ }),+ );+ return (+ <QueryClientProvider client={queryClient}>+ <NuqsTestingAdapter>{children}</NuqsTestingAdapter>+ </QueryClientProvider>+ );+}++function countHookRenders<T>(useHook: () => T) {+ const counter = { renders: 0 };+ const view = renderHook(+ () => {+ counter.renders++;+ return useHook();+ },+ { wrapper: HookProviders },+ );+ return { ...view, counter };+}++function countComponentCommits(ui: ReactNode) {+ const onRender = vi.fn();+ const view = render(+ <Profiler id="subject" onRender={onRender}>+ {ui}+ </Profiler>,+ );+ return { ...view, onRender };+}++const initialState = useCopilotUIStore.getState();++beforeEach(() => {+ server.use(getGetV2ListChatConnectionsMockHandler200({ offers: [] }));+ useCopilotUIStore.setState({+ contextPanelWidth: DEFAULT_PANEL_WIDTH,+ copilotLlmModel: "standard",+ initialPrompt: null,+ sessionToDelete: null,+ isNotificationsEnabled: false,+ isSoundEnabled: true,+ showNotificationDialog: false,+ });+});++afterEach(() => {+ useCopilotUIStore.setState(initialState);+ window.localStorage.clear();+ window.sessionStorage.clear();+});++describe("copilot UI store readers", () => {+ it("useWorkflowImportAutoSubmit ignores unrelated writes", async () => {+ const { counter } = countHookRenders(() =>+ useWorkflowImportAutoSubmit({+ onSend: vi.fn().mockResolvedValue(undefined),+ setPendingFileParts: vi.fn(),+ }),+ );+ await settle();+ const before = counter.renders;++ writeUnrelatedField();++ expect(counter.renders).toBe(before);+ });++ it("useSessionDeletion ignores unrelated writes and follows sessionToDelete", async () => {+ const { result, counter } = countHookRenders(() => useSessionDeletion());+ await settle();+ const before = counter.renders;++ writeUnrelatedField();+ expect(counter.renders).toBe(before);++ act(() => {+ useCopilotUIStore+ .getState()+ .setSessionToDelete({ id: "s1", title: "A chat" });+ });+ expect(result.current.sessionToDelete).toEqual({+ id: "s1",+ title: "A chat",+ });+ });++ it("useLockedTierFallback ignores unrelated writes", async () => {+ const { counter } = countHookRenders(() =>+ useLockedTierFallback(undefined),+ );+ await settle();+ const before = counter.renders;++ writeUnrelatedField();+ expect(counter.renders).toBe(before);++ act(() => useCopilotUIStore.getState().setCopilotLlmModel("advanced"));+ expect(counter.renders).toBeGreaterThan(before);+ });++ it("useConnectionPicker ignores unrelated writes and follows the model", async () => {+ const { result, counter } = countHookRenders(() => useConnectionPicker());+ await waitFor(() => expect(result.current).toBeDefined());+ await settle();+ const before = counter.renders;++ writeUnrelatedField();+ expect(counter.renders).toBe(before);++ act(() => useCopilotUIStore.getState().setCopilotLlmModel("advanced"));+ expect(counter.renders).toBeGreaterThan(before);+ });++ it("useChatInput ignores unrelated writes and still picks up an initial prompt", async () => {+ const { result, counter } = countHookRenders(() =>+ useChatInput({ onSend: vi.fn(), inputId: "store-selectors-input" }),+ );+ await settle();+ const before = counter.renders;++ writeUnrelatedField();+ expect(counter.renders).toBe(before);++ act(() => useCopilotUIStore.getState().setInitialPrompt("Hello Otto"));+ await waitFor(() => expect(result.current.value).toBe("Hello Otto"));+ });++ it("NotificationToggle ignores unrelated writes", async () => {+ const { onRender } = countComponentCommits(<NotificationToggle />);+ await settle();+ onRender.mockClear();++ writeUnrelatedField();+ expect(onRender).not.toHaveBeenCalled();++ act(() => useCopilotUIStore.getState().toggleSound());+ expect(onRender).toHaveBeenCalled();+ });++ it("NotificationDialog ignores unrelated writes", async () => {+ const { onRender } = countComponentCommits(<NotificationDialog />);+ await settle();+ onRender.mockClear();++ writeUnrelatedField();+ expect(onRender).not.toHaveBeenCalled();++ act(() => useCopilotUIStore.getState().setShowNotificationDialog(true));+ expect(onRender).toHaveBeenCalled();+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/useCopilotPage-store-selectors.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/useCopilotPage-store-selectors.test.tsxnew file mode 100644index 0000000000..eb493a8229--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/useCopilotPage-store-selectors.test.tsx@@ -0,0 +1,201 @@+import { act, renderHook } from "@/tests/integrations/test-utils";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++// The page hook reads three fields of the copilot UI store. A write to any+// other field (a panel resize writes `contextPanelWidth` every frame of a+// drag) must not re-render it, because it re-renders the whole chat host.++const streamState = vi.hoisted(() => ({+ status: "ready" as "ready" | "submitted" | "streaming" | "error",+}));+const flags = vi.hoisted(() => ({ brainDump: false }));++const sendNewMessage = vi.hoisted(() => vi.fn());+const completeGreeting = vi.hoisted(() => vi.fn());+const queueFollowUpMessage = vi.hoisted(() => vi.fn());+const queueMessage = vi.hoisted(() => vi.fn());+const setPendingFileParts = vi.hoisted(() => vi.fn());++vi.mock("@/services/feature-flags/use-get-flag", () => ({+ Flag: {+ CHAT_MODE_OPTION: "chat-mode-option",+ HIRE_EXPERTS: "hire-experts",+ ONBOARDING_BRAIN_DUMP: "onboarding-brain-dump",+ },+ useGetFlag: (flag: string) =>+ flag === "onboarding-brain-dump" ? flags.brainDump : false,+}));++vi.mock("nuqs", () => ({+ parseAsString: {},+ useQueryState: () => [null, vi.fn()],+}));++vi.mock("@/lib/auth/hooks/useAuth", () => ({+ useAuth: () => ({+ user: { id: "user-1" },+ isUserLoading: false,+ isLoggedIn: true,+ }),+}));++vi.mock("@/app/api/__generated__/endpoints/brain-dump/brain-dump", () => ({+ useCompleteBrainDumpGreeting: () => ({ mutate: completeGreeting }),+}));++vi.mock("../useExpertMap", async (importOriginal) => {+ const actual = await importOriginal<typeof import("../useExpertMap")>();+ return {+ ...actual,+ useExpertMap: () => ({+ expertsById: new Map(),+ isLoadingExperts: false,+ hasExpertsSettled: true,+ hasExpertsErrored: false,+ }),+ };+});++vi.mock("../useChatSession", () => ({+ useChatSession: () => ({+ sessionId: "session-1",+ setSessionId: vi.fn(),+ sessionLlmAuthProvider: "platform",+ sessionExpertId: null,+ isAdoptingExpertSession: false,+ hydratedMessages: [],+ rawSessionMessages: [],+ historicalTurnStats: new Map(),+ hasActiveStream: false,+ activeStreamStartedAt: null,+ hasMoreMessages: false,+ oldestSequence: null,+ isLoadingSession: false,+ isSessionError: false,+ createSession: vi.fn(),+ isCreatingSession: false,+ refetchSession: vi.fn(),+ sessionDryRun: false,+ sessionChatStatus: "idle",+ }),+}));++vi.mock("../useCopilotStream", () => ({+ useCopilotStream: () => ({+ messages: [],+ setMessages: vi.fn(),+ sendMessage: vi.fn(),+ stop: vi.fn(),+ status: streamState.status,+ error: undefined,+ isReconnecting: false,+ isFinishProbing: false,+ isRestoringActiveSession: false,+ isSyncing: false,+ isUserStoppingRef: { current: false },+ isUserStopping: false,+ rateLimitMessage: null,+ dismissRateLimit: vi.fn(),+ }),+}));++vi.mock("../useSendMessage", async (importOriginal) => {+ const actual = await importOriginal<typeof import("../useSendMessage")>();+ return {+ ...actual,+ useSendMessage: () => ({+ onSend: sendNewMessage,+ isUploadingFiles: false,+ setPendingFileParts,+ }),+ };+});++vi.mock("../useLoadMoreMessages", () => ({+ useLoadMoreMessages: () => ({+ pagedMessages: [],+ pagedTurnStats: new Map(),+ hasMore: false,+ isLoadingMore: false,+ loadMore: vi.fn(),+ }),+}));++vi.mock("../useCopilotPendingChips", () => ({+ useCopilotPendingChips: () => ({ queuedMessages: [], queueMessage }),+}));++vi.mock("../useCopilotNotifications", () => ({+ useCopilotNotifications: () => undefined,+}));+vi.mock("../useSessionTitlePoll", () => ({+ useSessionTitlePoll: () => undefined,+}));+vi.mock("../useExpertKickoff", () => ({+ useExpertKickoff: () => ({ isKickoffStarting: false }),+}));+vi.mock("../helpers/queueFollowUpMessage", () => ({ queueFollowUpMessage }));++import { DEFAULT_PANEL_WIDTH, useCopilotUIStore } from "../store";+import { useCopilotPage } from "../useCopilotPage";++const initialState = useCopilotUIStore.getState();++beforeEach(() => {+ streamState.status = "ready";+ flags.brainDump = false;+ sendNewMessage.mockResolvedValue(undefined);+ useCopilotUIStore.setState({+ contextPanelWidth: DEFAULT_PANEL_WIDTH,+ copilotLlmModel: "standard",+ isDryRun: false,+ initialPrompt: null,+ });+});++afterEach(() => {+ useCopilotUIStore.setState(initialState);+ vi.clearAllMocks();+ window.sessionStorage.clear();+ window.localStorage.clear();+});++function renderCountedPage() {+ const counter = { renders: 0 };+ const view = renderHook(() => {+ counter.renders++;+ return useCopilotPage();+ });+ return { ...view, counter };+}++describe("useCopilotPage — copilot UI store reads", () => {+ it("does not re-render for writes to fields it does not read", async () => {+ const { counter } = renderCountedPage();+ await act(async () => {});+ const before = counter.renders;++ act(() => {+ const store = useCopilotUIStore.getState();+ store.setContextPanelWidth(DEFAULT_PANEL_WIDTH + 40);+ store.setArtifactPanelWidth(700);+ store.setDrawerOpen(true);+ store.setSearchOpen(true);+ });++ expect(counter.renders).toBe(before);+ });++ it("still re-renders when the model or dry-run setting changes", async () => {+ const { counter } = renderCountedPage();+ await act(async () => {});+ const before = counter.renders;++ act(() => useCopilotUIStore.getState().setCopilotLlmModel("advanced"));+ expect(counter.renders).toBeGreaterThan(before);++ const afterModel = counter.renders;+ act(() => useCopilotUIStore.getState().setIsDryRun(true));+ expect(counter.renders).toBeGreaterThan(afterModel);+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsxindex 7be9fcffea..d0af13f44e 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx@@ -163,7 +163,8 @@ export function ChatInput({canAttachWhileStreaming = false,atReset,}: Props) {- const { isDryRun, setIsDryRun } = useCopilotUIStore();+ const isDryRun = useCopilotUIStore((s) => s.isDryRun);+ const setIsDryRun = useCopilotUIStore((s) => s.setIsDryRun);// Still the CHAT_MODE_OPTION flag, which no longer names what it gates: the// Fast/Thinking control it was created for is gone. Renaming it means an// LaunchDarkly change, so it is left until the combined picker restructuresdiff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsxindex 39237b2a31..cc27e7f887 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx@@ -79,21 +79,22 @@ const mockSetInitialPrompt = vi.fn((value: string | null) => {});vi.mock("@/app/(platform)/copilot/store", () => ({- useCopilotUIStore: () => ({- copilotLlmModel: mockCopilotLlmModel,- setCopilotLlmModel: mockSetCopilotLlmModel,- copilotLlmAuth: {- authProvider: mockCopilotLlmAuthProvider,- credentialId: null,- },- setCopilotLlmAuth: vi.fn(),- isDryRun: false,- setIsDryRun: vi.fn(),- initialPrompt: mockInitialPrompt,- setInitialPrompt: mockSetInitialPrompt,- sentMessageCount: 0,- notifyMessageSent: vi.fn(),- }),+ useCopilotUIStore: (selector: (state: Record<string, unknown>) => unknown) =>+ selector({+ copilotLlmModel: mockCopilotLlmModel,+ setCopilotLlmModel: mockSetCopilotLlmModel,+ copilotLlmAuth: {+ authProvider: mockCopilotLlmAuthProvider,+ credentialId: null,+ },+ setCopilotLlmAuth: vi.fn(),+ isDryRun: false,+ setIsDryRun: vi.fn(),+ initialPrompt: mockInitialPrompt,+ setInitialPrompt: mockSetInitialPrompt,+ sentMessageCount: 0,+ notifyMessageSent: vi.fn(),+ }),}));let mockFlagValue = false;diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInputAttachmentCap.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInputAttachmentCap.test.tsxindex 901f9c3cef..2ffd685a79 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInputAttachmentCap.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInputAttachmentCap.test.tsx@@ -22,18 +22,19 @@ vi.mock("@/app/api/__generated__/endpoints/chat/chat", () => ({}));vi.mock("@/app/(platform)/copilot/store", () => ({- useCopilotUIStore: () => ({- copilotLlmModel: "standard",- setCopilotLlmModel: vi.fn(),- copilotLlmAuth: { authProvider: "platform", credentialId: null },- setCopilotLlmAuth: vi.fn(),- isDryRun: false,- setIsDryRun: vi.fn(),- initialPrompt: null,- setInitialPrompt: vi.fn(),- sentMessageCount: 0,- notifyMessageSent: vi.fn(),- }),+ useCopilotUIStore: (selector: (state: Record<string, unknown>) => unknown) =>+ selector({+ copilotLlmModel: "standard",+ setCopilotLlmModel: vi.fn(),+ copilotLlmAuth: { authProvider: "platform", credentialId: null },+ setCopilotLlmAuth: vi.fn(),+ isDryRun: false,+ setIsDryRun: vi.fn(),+ initialPrompt: null,+ setInitialPrompt: vi.fn(),+ sentMessageCount: 0,+ notifyMessageSent: vi.fn(),+ }),}));vi.mock("@/services/feature-flags/use-get-flag", () => ({diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInputComposerRow.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInputComposerRow.test.tsxindex c39d3ff6ac..05608fa47a 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInputComposerRow.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInputComposerRow.test.tsx@@ -48,21 +48,22 @@ vi.mock("@/app/api/__generated__/endpoints/chat/chat", () => ({}));vi.mock("@/app/(platform)/copilot/store", () => ({- useCopilotUIStore: () => ({- copilotChatMode: "extended_thinking",- setCopilotChatMode: vi.fn(),- copilotModePinned: false,- copilotLlmModel: "standard",- setCopilotLlmModel: vi.fn(),- copilotLlmAuth: { authProvider: "platform", credentialId: null },- setCopilotLlmAuth: vi.fn(),- isDryRun: false,- setIsDryRun: vi.fn(),- initialPrompt: null,- setInitialPrompt: vi.fn(),- sentMessageCount: 0,- notifyMessageSent: vi.fn(),- }),+ useCopilotUIStore: (selector: (state: Record<string, unknown>) => unknown) =>+ selector({+ copilotChatMode: "extended_thinking",+ setCopilotChatMode: vi.fn(),+ copilotModePinned: false,+ copilotLlmModel: "standard",+ setCopilotLlmModel: vi.fn(),+ copilotLlmAuth: { authProvider: "platform", credentialId: null },+ setCopilotLlmAuth: vi.fn(),+ isDryRun: false,+ setIsDryRun: vi.fn(),+ initialPrompt: null,+ setInitialPrompt: vi.fn(),+ sentMessageCount: 0,+ notifyMessageSent: vi.fn(),+ }),}));vi.mock("@/services/feature-flags/use-get-flag", () => ({diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/chatDraft.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/chatDraft.test.tsxindex cc48fae080..bfb8cea946 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/chatDraft.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/chatDraft.test.tsx@@ -8,13 +8,14 @@ vi.mock("@/lib/auth/hooks/useAuthStore", () => ({useAuthStore: (selector: (state: typeof auth) => unknown) => selector(auth),}));vi.mock("@/app/(platform)/copilot/store", () => ({- useCopilotUIStore: () => ({- initialPrompt: prompts.initialPrompt,- setInitialPrompt: (value: string | null) => {- prompts.initialPrompt = value;- },- notifyMessageSent: vi.fn(),- }),+ useCopilotUIStore: (selector: (state: Record<string, unknown>) => unknown) =>+ selector({+ initialPrompt: prompts.initialPrompt,+ setInitialPrompt: (value: string | null) => {+ prompts.initialPrompt = value;+ },+ notifyMessageSent: vi.fn(),+ }),}));import { useChatDraftAccess } from "../useChatDraft";import { useChatInput } from "../useChatInput";diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/useConnectionPicker.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/useConnectionPicker.tsindex 80ff52c10a..2274e17b50 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/useConnectionPicker.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/useConnectionPicker.ts@@ -18,12 +18,10 @@ export function useConnectionPicker() {const query = useGetV2ListChatConnections({query: { refetchOnWindowFocus: true, staleTime: 0 },});- const {- copilotLlmAuth,- setCopilotLlmAuth,- copilotLlmModel,- setCopilotLlmModel,- } = useCopilotUIStore();+ const copilotLlmAuth = useCopilotUIStore((s) => s.copilotLlmAuth);+ const setCopilotLlmAuth = useCopilotUIStore((s) => s.setCopilotLlmAuth);+ const copilotLlmModel = useCopilotUIStore((s) => s.copilotLlmModel);+ const setCopilotLlmModel = useCopilotUIStore((s) => s.setCopilotLlmModel);const offers = visibleOffers(query.data?.status === 200 ? query.data.data.offers : undefined,diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/useLockedTierFallback.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/useLockedTierFallback.tsindex 2f359b74db..5679f0f09a 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/useLockedTierFallback.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/useLockedTierFallback.ts@@ -7,7 +7,8 @@ import { tierLock } from "./helpers";// A plan that lapsed with Advanced chosen leaves "advanced" stored, and every// send is then refused. The server locks Advanced only on a definite "not entitled".export function useLockedTierFallback(active: AIConnectionOffer | undefined) {- const { copilotLlmModel, setCopilotLlmModel } = useCopilotUIStore();+ const copilotLlmModel = useCopilotUIStore((s) => s.copilotLlmModel);+ const setCopilotLlmModel = useCopilotUIStore((s) => s.setCopilotLlmModel);const advancedLocked = Boolean(tierLock(active, "advanced"));useEffect(() => {if (advancedLocked && copilotLlmModel === "advanced")diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.tsindex 640b2bc66d..8c9b986875 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts@@ -39,13 +39,11 @@ export function useChatInput({// unlike state which batches and can leave a gap for a second call.const isSubmittingRef = useRef(false);const isEnqueueingRef = useRef(false);- const {- initialPrompt,- setInitialPrompt,- recoveredDraft,- clearRecoveredDraft,- notifyMessageSent,- } = useCopilotUIStore();+ const initialPrompt = useCopilotUIStore((s) => s.initialPrompt);+ const setInitialPrompt = useCopilotUIStore((s) => s.setInitialPrompt);+ const recoveredDraft = useCopilotUIStore((s) => s.recoveredDraft);+ const clearRecoveredDraft = useCopilotUIStore((s) => s.clearRecoveredDraft);+ const notifyMessageSent = useCopilotUIStore((s) => s.notifyMessageSent);useEffect(function consumeInitialPrompt() {diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsxindex 2bec3b1ffe..475bf8c864 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx@@ -59,7 +59,10 @@ export function ChatSidebar() {const { state } = useSidebar();const isCollapsed = state === "collapsed";const [sessionId, setSessionId] = useQueryState("sessionId", parseAsString);- const { completedSessionIDs, clearCompletedSession } = useCopilotUIStore();+ const completedSessionIDs = useCopilotUIStore((s) => s.completedSessionIDs);+ const clearCompletedSession = useCopilotUIStore(+ (s) => s.clearCompletedSession,+ );const openSearch = useGlobalSearchStore((state) => state.openSearch);const closeSearch = useGlobalSearchStore((state) => state.closeSearch);const isChatSearchEnabled = useGetFlag(Flag.CHAT_SEARCH);diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/__tests__/ChatSidebar.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/__tests__/ChatSidebar.test.tsxindex 3ec7c372f4..0575e3503c 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/__tests__/ChatSidebar.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/__tests__/ChatSidebar.test.tsx@@ -4,6 +4,7 @@ import {} from "@/app/api/__generated__/endpoints/chat/chat.msw";import { server } from "@/mocks/mock-server";import {+ act,fireEvent,render,screen,@@ -14,6 +15,7 @@ import { http, HttpResponse } from "msw";import { parseAsString, useQueryState } from "nuqs";import { withNuqsTestingAdapter } from "nuqs/adapters/testing";import userEvent from "@testing-library/user-event";+import { Profiler } from "react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { useGlobalSearchStore } from "@/app/(platform)/components/GlobalSearchModal/useGlobalSearchStore";import { useCopilotUIStore } from "../../../store";@@ -701,3 +703,43 @@ describe("ChatSidebar — rename", () => {});});});++describe("ChatSidebar — copilot UI store reads", () => {+ beforeEach(() => {+ useCopilotUIStore.setState({+ sessionToDelete: null,+ completedSessionIDs: new Set(),+ });+ server.use(+ getGetV2ListSessionsMockHandler200({ sessions, total: sessions.length }),+ );+ });++ afterEach(() => {+ server.resetHandlers();+ });++ it("does not re-render while a panel resize writes its width", async () => {+ const onRender = vi.fn();+ render(+ <SidebarProvider>+ <Profiler id="chat-sidebar" onRender={onRender}>+ <ChatSidebar />+ </Profiler>+ </SidebarProvider>,+ );+ await screen.findByText("Other chat");+ await act(async () => {});+ onRender.mockClear();++ act(() => {+ const store = useCopilotUIStore.getState();+ store.setContextPanelWidth(store.contextPanelWidth + 40);+ store.setArtifactPanelWidth(store.artifactPanelWidth + 40);+ });+ expect(onRender).not.toHaveBeenCalled();++ act(() => useCopilotUIStore.getState().addCompletedSession("s2"));+ expect(onRender).toHaveBeenCalled();+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/components/NotificationToggle/NotificationToggle.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/components/NotificationToggle/NotificationToggle.tsxindex 3cf30a42fd..237f9228c0 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/components/NotificationToggle/NotificationToggle.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/components/NotificationToggle/NotificationToggle.tsx@@ -18,12 +18,14 @@ import {import { Icon } from "@/components/atoms/Icon/Icon";export function NotificationToggle() {- const {- isNotificationsEnabled,- setNotificationsEnabled,- isSoundEnabled,- toggleSound,- } = useCopilotUIStore();+ const isNotificationsEnabled = useCopilotUIStore(+ (s) => s.isNotificationsEnabled,+ );+ const setNotificationsEnabled = useCopilotUIStore(+ (s) => s.setNotificationsEnabled,+ );+ const isSoundEnabled = useCopilotUIStore((s) => s.isSoundEnabled);+ const toggleSound = useCopilotUIStore((s) => s.toggleSound);async function handleToggleNotifications() {if (isNotificationsEnabled) {diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsxindex 923ecc5059..bdac43f059 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsx@@ -35,14 +35,14 @@ export function MobileDrawer() {"sessionId",parseAsString,);- const {- completedSessionIDs,- clearCompletedSession,- isDrawerOpen,- setDrawerOpen,- isSearchOpen,- setSearchOpen,- } = useCopilotUIStore();+ const completedSessionIDs = useCopilotUIStore((s) => s.completedSessionIDs);+ const clearCompletedSession = useCopilotUIStore(+ (s) => s.clearCompletedSession,+ );+ const isDrawerOpen = useCopilotUIStore((s) => s.isDrawerOpen);+ const setDrawerOpen = useCopilotUIStore((s) => s.setDrawerOpen);+ const isSearchOpen = useCopilotUIStore((s) => s.isSearchOpen);+ const setSearchOpen = useCopilotUIStore((s) => s.setSearchOpen);const isChatSearchEnabled = useGetFlag(Flag.CHAT_SEARCH);const isSearchActive = isChatSearchEnabled && isSearchOpen;const sessionNeedsReload = useCopilotChatRuntimeStore(diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/NotificationDialog/NotificationDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/NotificationDialog/NotificationDialog.tsxindex 7d2b9e1fab..7d775e699d 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/NotificationDialog/NotificationDialog.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/NotificationDialog/NotificationDialog.tsx@@ -10,12 +10,18 @@ import { BellRingIcon } from "@hugeicons/core-free-icons";import { Icon } from "@/components/atoms/Icon/Icon";export function NotificationDialog() {- const {- showNotificationDialog,- setShowNotificationDialog,- setNotificationsEnabled,- isNotificationsEnabled,- } = useCopilotUIStore();+ const showNotificationDialog = useCopilotUIStore(+ (s) => s.showNotificationDialog,+ );+ const setShowNotificationDialog = useCopilotUIStore(+ (s) => s.setShowNotificationDialog,+ );+ const setNotificationsEnabled = useCopilotUIStore(+ (s) => s.setNotificationsEnabled,+ );+ const isNotificationsEnabled = useCopilotUIStore(+ (s) => s.isNotificationsEnabled,+ );const [dismissed, setDismissed] = useState(() => storage.get(Key.COPILOT_NOTIFICATION_DIALOG_DISMISSED) === "true",diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/PanelResizeHandle.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/PanelResizeHandle.tsxindex ccae05fce4..4abe6d36a0 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/PanelResizeHandle.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/PanelResizeHandle.tsx@@ -18,6 +18,29 @@ interface Props {onResizingChange?: (isResizing: boolean) => void;}+// A drag reports at most one width per animation frame: pointer moves arrive+// faster than the screen paints, and every width written re-renders the panel.+interface PendingWidth {+ width: number | null;+ frame: number | null;+}++// Reports the pending width, if any, and cancels its scheduled frame. Called+// once per frame during a drag, and on pointer up/cancel/unmount before the+// drag ends, so the panel applies the last width with its tween still off.+function commitPendingWidth(+ pending: PendingWidth,+ onWidthChange: (width: number) => void,+) {+ if (pending.frame != null) {+ cancelAnimationFrame(pending.frame);+ pending.frame = null;+ }+ const width = pending.width;+ pending.width = null;+ if (width != null) onWidthChange(width);+}+export function PanelResizeHandle({panelSelector,onWidthChange,@@ -43,6 +66,8 @@ export function PanelResizeHandle({const onResizingChangeRef = useRef(onResizingChange);onResizingChangeRef.current = onResizingChange;+ const pendingRef = useRef<PendingWidth>({ width: null, frame: null });+useEffect(() => {onResizingChangeRef.current?.(isDragging);}, [isDragging]);@@ -54,6 +79,7 @@ export function PanelResizeHandle({// dragging, torn down on unmount so closing the panel mid-drag is safe.useEffect(() => {if (!isDragging) return;+ const pending = pendingRef.current;function handlePointerMove(moveEvent: PointerEvent) {const delta = startXRef.current - moveEvent.clientX;@@ -66,10 +92,16 @@ export function PanelResizeHandle({effectiveMax,Math.max(minWidthRef.current, startWidthRef.current + delta),);- onWidthChangeRef.current(newWidth);+ pending.width = newWidth;+ if (pending.frame != null) return;+ pending.frame = requestAnimationFrame(() => {+ pending.frame = null;+ commitPendingWidth(pending, onWidthChangeRef.current);+ });}function handlePointerUp() {+ commitPendingWidth(pending, onWidthChangeRef.current);setIsDragging(false);}@@ -80,6 +112,8 @@ export function PanelResizeHandle({document.removeEventListener("pointermove", handlePointerMove);document.removeEventListener("pointerup", handlePointerUp);document.removeEventListener("pointercancel", handlePointerUp);+ // Closing the panel mid-drag still keeps the last width.+ commitPendingWidth(pending, onWidthChangeRef.current);};}, [isDragging]);@@ -113,6 +147,7 @@ export function PanelResizeHandle({}pointerIdRef.current = null;}+ commitPendingWidth(pendingRef.current, onWidthChangeRef.current);setIsDragging(false);}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/__tests__/PanelResizeHandle.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/__tests__/PanelResizeHandle.test.tsxnew file mode 100644index 0000000000..bc54fcd132--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/__tests__/PanelResizeHandle.test.tsx@@ -0,0 +1,164 @@+import {+ act,+ fireEvent,+ render,+ screen,+} from "@/tests/integrations/test-utils";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { PanelResizeHandle } from "../PanelResizeHandle";++// The handle hands the panel at most one new width per animation frame, and+// the last one when the pointer comes up, so a drag does not write to the+// store (and re-render every subscriber) on each pointer move.++const PANEL_WIDTH = 400;+const CONTAINER_WIDTH = 1600;+const START_X = 1000;++let frames: Map<number, FrameRequestCallback>;+let nextFrameID: number;++function runFrame() {+ const queued = [...frames.values()];+ frames.clear();+ act(() => queued.forEach((callback) => callback(performance.now())));+}++function renderHandle() {+ const onWidthChange = vi.fn();+ const onResizingChange = vi.fn();+ const view = render(+ <div data-container>+ <div data-panel>+ <PanelResizeHandle+ panelSelector="[data-panel]"+ onWidthChange={onWidthChange}+ onResizingChange={onResizingChange}+ minWidth={200}+ maxWidth={800}+ reservedWidth={0}+ />+ </div>+ </div>,+ );+ const handle = screen.getByRole("separator", { name: "Resize panel" });+ return { ...view, handle, onWidthChange, onResizingChange };+}++function moveTo(clientX: number) {+ fireEvent.pointerMove(document, { clientX });+}++beforeEach(() => {+ frames = new Map();+ nextFrameID = 1;+ vi.spyOn(window, "requestAnimationFrame").mockImplementation((callback) => {+ const id = nextFrameID++;+ frames.set(id, callback);+ return id;+ });+ vi.spyOn(window, "cancelAnimationFrame").mockImplementation((id) => {+ frames.delete(id);+ });+ vi.spyOn(HTMLElement.prototype, "offsetWidth", "get").mockImplementation(+ function (this: HTMLElement) {+ if (this.hasAttribute("data-panel")) return PANEL_WIDTH;+ if (this.hasAttribute("data-container")) return CONTAINER_WIDTH;+ return 0;+ },+ );+});++afterEach(() => {+ vi.restoreAllMocks();+});++describe("PanelResizeHandle", () => {+ it("writes one width for ten pointer moves within one frame", () => {+ const { handle, onWidthChange } = renderHandle();++ fireEvent.pointerDown(handle, { clientX: START_X, pointerId: 1 });+ for (let step = 1; step <= 10; step++) moveTo(START_X - step);++ expect(onWidthChange).not.toHaveBeenCalled();+ runFrame();++ expect(onWidthChange).toHaveBeenCalledTimes(1);+ expect(onWidthChange).toHaveBeenCalledWith(PANEL_WIDTH + 10);+ });++ it("writes the latest width once per frame across a longer drag", () => {+ const { handle, onWidthChange } = renderHandle();++ fireEvent.pointerDown(handle, { clientX: START_X, pointerId: 1 });+ moveTo(START_X - 5);+ moveTo(START_X - 20);+ runFrame();+ moveTo(START_X - 30);+ runFrame();+ runFrame();++ expect(onWidthChange.mock.calls).toEqual([+ [PANEL_WIDTH + 20],+ [PANEL_WIDTH + 30],+ ]);+ });++ it("commits the pending width when the pointer comes up, before the drag ends", () => {+ const { handle, onWidthChange, onResizingChange } = renderHandle();++ fireEvent.pointerDown(handle, { clientX: START_X, pointerId: 1 });+ moveTo(START_X - 50);+ onResizingChange.mockClear();+ fireEvent.pointerUp(handle, { clientX: START_X - 50, pointerId: 1 });++ expect(onWidthChange).toHaveBeenCalledTimes(1);+ expect(onWidthChange).toHaveBeenCalledWith(PANEL_WIDTH + 50);+ // The panel still drops its width tween for the final write.+ expect(onWidthChange.mock.invocationCallOrder[0]).toBeLessThan(+ onResizingChange.mock.invocationCallOrder[0],+ );+ expect(onResizingChange).toHaveBeenLastCalledWith(false);++ runFrame();+ moveTo(START_X - 80);+ runFrame();+ expect(onWidthChange).toHaveBeenCalledTimes(1);+ });++ it("commits the pending width on a document-level pointer cancel", () => {+ const { handle, onWidthChange } = renderHandle();++ fireEvent.pointerDown(handle, { clientX: START_X, pointerId: 1 });+ moveTo(START_X + 100);+ fireEvent.pointerCancel(document);++ expect(onWidthChange).toHaveBeenCalledTimes(1);+ expect(onWidthChange).toHaveBeenCalledWith(PANEL_WIDTH - 100);+ expect(frames.size).toBe(0);+ });++ it("commits the pending width when the panel closes mid-drag", () => {+ const { handle, onWidthChange, unmount } = renderHandle();++ fireEvent.pointerDown(handle, { clientX: START_X, pointerId: 1 });+ moveTo(START_X - 40);+ unmount();++ expect(onWidthChange).toHaveBeenCalledTimes(1);+ expect(onWidthChange).toHaveBeenCalledWith(PANEL_WIDTH + 40);+ expect(frames.size).toBe(0);+ });++ it("still clamps the width to the panel's limits", () => {+ const { handle, onWidthChange } = renderHandle();++ fireEvent.pointerDown(handle, { clientX: START_X, pointerId: 1 });+ moveTo(START_X - 900);+ runFrame();+ moveTo(START_X + 900);+ runFrame();++ expect(onWidthChange.mock.calls).toEqual([[800], [200]]);+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.tsindex ed3bb5ff74..0669c9f10a 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts@@ -126,7 +126,9 @@ export function useCopilotPage({setKickoffParam,]);- const { copilotLlmModel, isDryRun, setInitialPrompt } = useCopilotUIStore();+ const copilotLlmModel = useCopilotUIStore((s) => s.copilotLlmModel);+ const isDryRun = useCopilotUIStore((s) => s.isDryRun);+ const setInitialPrompt = useCopilotUIStore((s) => s.setInitialPrompt);const { mutate: completeGreeting } = useCompleteBrainDumpGreeting();const {diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useSessionDeletion.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useSessionDeletion.tsindex 58c845534a..2b0a7449f6 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useSessionDeletion.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useSessionDeletion.ts@@ -27,7 +27,8 @@ export function useSessionDeletion() {sessionId: parseAsString,expertId: parseAsString,});- const { sessionToDelete, setSessionToDelete } = useCopilotUIStore();+ const sessionToDelete = useCopilotUIStore((s) => s.sessionToDelete);+ const setSessionToDelete = useCopilotUIStore((s) => s.setSessionToDelete);const { mutate: deleteSession, isPending: isDeleting } =useDeleteV2DeleteSession({diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useWorkflowImportAutoSubmit.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useWorkflowImportAutoSubmit.tsindex 1296a8b40f..e15071b981 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useWorkflowImportAutoSubmit.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useWorkflowImportAutoSubmit.ts@@ -103,7 +103,7 @@ export function useWorkflowImportAutoSubmit({setPendingFileParts: (parts: FileUIPart[]) => void;isSendLocked?: boolean;}) {- const { setInitialPrompt } = useCopilotUIStore();+ const setInitialPrompt = useCopilotUIStore((s) => s.setInitialPrompt);const hasProcessedUrlPrompt = useRef(false);useEffect(() => {diff --git a/docs/engineering/frontend-perf-baseline.md b/docs/engineering/frontend-perf-baseline.mdindex 2d88940973..2ca24f14da 100644--- a/docs/engineering/frontend-perf-baseline.md+++ b/docs/engineering/frontend-perf-baseline.md@@ -581,3 +581,51 @@ Added with SECRT-2995 and measured on `dev` at `a1578ad9a`, before that change.| `Popper props:children` | 6,770 || `PopperAnchor props:children` | 6,770 || `PopperProvider props:children` | 6,770 |++## copilot-resize-drag · baseline — median of 3 runs++Added with the scenario (SECRT-2999): `dev` at `6d793e53d`, same machine type, 1 warm-up and 3 saved runs. Every pointer move of the drag wrote the panel width to the copilot UI store, and the page hook read the whole store, so each move re-rendered the whole 200-message transcript: about 3,000 renders per commit and one long task per move.++| metric | median | range | spread |+| --- | --- | --- | --- |+| commits | 193 | 190 – 196 | 3.1% |+| total renders | 574,244 | 574,001 – 574,251 | 0.0% |+| renders per commit | 2,975.4 | 2,929.9 – 3,021.1 | 3.1% |+| max renders in one commit | 9,498 | 9,498 – 9,498 | 0.0% |+| script time (ms) | 17,819 | 17,358 – 18,387 | 5.8% |+| task time (ms) | 20,508 | 19,966 – 20,952 | 4.8% |+| layout time (ms) | 575 | 575 – 577 | 0.4% |+| style recalc time (ms) | 34 | 34 – 35 | 2.1% |+| long tasks (≥ 50 ms) | 60 | 60 – 60 | 0.0% |+| long task total (ms) | 19,661 | 19,213 – 20,218 | 5.1% |+| heap used after GC (MB) | 86.5 | 84.1 – 95.6 | 13.4% |++**Top components (median renders)**++| name | renders |+| --- | --- |+| `Tooltip` | 41,418 |+| `TooltipContent` | 41,418 |+| `HugeiconsIcon` | 24,264 |+| `Icon` | 24,264 |+| `Presence` | 22,172 |+| `Popper` | 21,204 |+| `PopperAnchor` | 21,204 |+| `PopperProvider` | 21,204 |+| `Primitive.button` | 21,204 |+| `Primitive.button.Slot` | 21,204 |++**Top render causes (median renders)**++| name | renders |+| --- | --- |+| `Tooltip props:children` | 41,298 |+| `HugeiconsIcon parent-same-props<-Icon` | 24,264 |+| `Presence props:children` | 22,172 |+| `Primitive.div props:children` | 21,204 |+| `Primitive.div.Slot props:children` | 21,204 |+| `Primitive.div.SlotClone props:children` | 21,204 |+| `Popper props:children` | 20,955 |+| `PopperAnchor props:children` | 20,955 |+| `PopperProvider props:children` | 20,955 |+| `TooltipProvider props:children` | 20,949 |diff --git a/docs/engineering/frontend-perf-measurement.md b/docs/engineering/frontend-perf-measurement.mdindex f18c890531..b723c668e5 100644--- a/docs/engineering/frontend-perf-measurement.md+++ b/docs/engineering/frontend-perf-measurement.md@@ -124,6 +124,7 @@ Names come from the component function. Third-party code bundled already minifie| `library-running-events` | Open the same library at `/library?sort=updatedAt`, with the websocket mocked | Push a `graph_execution_event` for one of the 20 runs every 250 ms, 80 in all; print the `subscribe_graph_executions` frames and `GET /executions` requests seen | 20 s of events + 2 s || `builder-run-events` | Open the same 50-node workflow with its RUNNING run; the harness answers the websocket subscribe for that run itself | 40 node execution events over the websocket, one every 50 ms: the 10 unfinished nodes go RUNNING then COMPLETED, each event sent twice. The execution GET returns what has been sent so far, as the backend would | 2 s after the last event || `copilot-tool-wait` | Open the 200-message chat, send "go", and wait until the reply's one tool call shows "Running Perf lookup…". The reply then sends only `: heartbeat` comments, so the turn stays on that tool | Nothing | 20 s |+| `copilot-resize-drag` | Open the 200-message chat and click "Open files" so the files panel docks on the right | Drag the panel's resize handle 120 px wider with 60 pointer moves over 1 s | 1 s after the drop |Each scenario's `readyWhen` field says exactly what setup waits for before the window opens. Most wait for the page's own content, then for network idle (at most 15 s, because some pages poll), then one more second.