Skip to content

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/builder): isolate canvas renders, batch loads, memo block menu (#15726)

Abhimanyu Yadav5684067ba27f
diff --git a/autogpt_platform/frontend/scripts/perf/scenarios/builder-block-menu-search.ts b/autogpt_platform/frontend/scripts/perf/scenarios/builder-block-menu-search.ts
new file mode 100644
index 0000000000..e7c4bfa2b0
--- /dev/null
+++ b/autogpt_platform/frontend/scripts/perf/scenarios/builder-block-menu-search.ts
@@ -0,0 +1,55 @@
+import { BuildPage } from "../../../src/playwright/pages/build.page";
+import { createBuilderFixture } from "../lib/builder-fixture";
+import { installRoutes } from "../lib/routes";
+import { settle, type Scenario } from "../lib/scenario";
+
+const QUERY = "text";
+const KEY_DELAY_MS = 120;
+const SCROLLS = 6;
+const SCROLL_PX = 800;
+const SCROLL_PAUSE_MS = 400;
+const READY_TIMEOUT_MS = 60_000;
+
+export const builderBlockMenuSearch: Scenario = {
+ name: "builder-block-menu-search",
+ description: `Open the block menu over an idle 50-node workflow, type "${QUERY}" into its search, then scroll the results ${SCROLLS} times so more pages load.`,
+ readyWhen:
+ "all 50 nodes are on the canvas and the block menu is open on its default view, then network idle + 1 s",
+ windowMs: 2_000,
+ async setup(ctx) {
+ const { page } = ctx;
+ const fixture = createBuilderFixture(ctx.userID);
+ await installRoutes(page, fixture.handlers);
+ const builder = new BuildPage(page);
+ await page.goto(`/build?flowID=${fixture.graph.id}`);
+ await builder.closeTutorial();
+ await page
+ .locator('[data-id^="custom-node-"]')
+ .nth(fixture.graph.nodes.length - 1)
+ .waitFor({ state: "attached", timeout: READY_TIMEOUT_MS });
+ await builder.openBlocksPanel();
+ const search = page.locator(
+ '[data-id="blocks-control-search-bar"] input[type="text"]',
+ );
+ await search.waitFor({ state: "visible", timeout: READY_TIMEOUT_MS });
+ await settle(page);
+ const menu = page.locator('[data-id="blocks-control-popover-content"]');
+ return {
+ async run() {
+ await search.click();
+ await page.keyboard.type(QUERY, { delay: KEY_DELAY_MS });
+ await menu
+ .locator('[data-id^="block-card-"]')
+ .first()
+ .waitFor({ state: "visible", timeout: READY_TIMEOUT_MS });
+ const box = await menu.boundingBox();
+ if (!box) throw new Error("Block menu has no bounding box");
+ await page.mouse.move(box.x + box.width * 0.75, box.y + box.height / 2);
+ for (let scroll = 0; scroll < SCROLLS; scroll++) {
+ await page.mouse.wheel(0, SCROLL_PX);
+ await page.waitForTimeout(SCROLL_PAUSE_MS);
+ }
+ },
+ };
+ },
+};
diff --git a/autogpt_platform/frontend/scripts/perf/scenarios/builder-load-graph.ts b/autogpt_platform/frontend/scripts/perf/scenarios/builder-load-graph.ts
new file mode 100644
index 0000000000..cd79e547e4
--- /dev/null
+++ b/autogpt_platform/frontend/scripts/perf/scenarios/builder-load-graph.ts
@@ -0,0 +1,58 @@
+import { BuildPage } from "../../../src/playwright/pages/build.page";
+import { buildGraph } from "../lib/builder-fixture";
+import { fulfillJSON, installRoutes } from "../lib/routes";
+import { settle, type Scenario } from "../lib/scenario";
+
+const SMALL_GRAPH_ID = "00000000-0000-4000-8000-0000000000c1";
+const LARGE_GRAPH_ID = "00000000-0000-4000-8000-0000000000c2";
+const LARGE_NODE_COUNT = 100;
+const READY_TIMEOUT_MS = 60_000;
+
+export const builderLoadGraph: Scenario = {
+ name: "builder-load-graph",
+ description: `From an open 1-node workflow, switch the builder to a saved ${LARGE_NODE_COUNT}-node workflow (client-side URL change) and load it.`,
+ readyWhen: "the 1-node workflow is on the canvas, then network idle + 1 s",
+ windowMs: 2_000,
+ async setup(ctx) {
+ const { page } = ctx;
+ const small = { ...buildGraph(ctx.userID, 1), id: SMALL_GRAPH_ID };
+ const large = {
+ ...buildGraph(ctx.userID, LARGE_NODE_COUNT),
+ id: LARGE_GRAPH_ID,
+ name: `Perf: ${LARGE_NODE_COUNT}-step workflow`,
+ };
+ const graphs = new Map([
+ [small.id, small],
+ [large.id, large],
+ ]);
+ await installRoutes(page, {
+ graph: async (route, match) => {
+ const graph = graphs.get(match[1]);
+ if (!graph || route.request().method() !== "GET") {
+ return route.fallback();
+ }
+ await fulfillJSON(route, graph);
+ },
+ });
+ const builder = new BuildPage(page);
+ await page.goto(`/build?flowID=${small.id}`);
+ await builder.closeTutorial();
+ const nodes = page.locator('[data-id^="custom-node-"]');
+ await nodes
+ .first()
+ .waitFor({ state: "attached", timeout: READY_TIMEOUT_MS });
+ await settle(page);
+ return {
+ async run() {
+ // The app router follows history.pushState, so this is the same
+ // client-side navigation as opening another workflow from the app.
+ await page.evaluate((url) => {
+ window.history.pushState(null, "", url);
+ }, `/build?flowID=${large.id}`);
+ await nodes
+ .nth(LARGE_NODE_COUNT - 1)
+ .waitFor({ state: "attached", timeout: READY_TIMEOUT_MS });
+ },
+ };
+ },
+};
diff --git a/autogpt_platform/frontend/scripts/perf/scenarios/builder-type-field.ts b/autogpt_platform/frontend/scripts/perf/scenarios/builder-type-field.ts
new file mode 100644
index 0000000000..4c9ee0ad62
--- /dev/null
+++ b/autogpt_platform/frontend/scripts/perf/scenarios/builder-type-field.ts
@@ -0,0 +1,41 @@
+import { BuildPage } from "../../../src/playwright/pages/build.page";
+import { createBuilderFixture } from "../lib/builder-fixture";
+import { installRoutes } from "../lib/routes";
+import { settle, type Scenario } from "../lib/scenario";
+
+const TEXT = "twenty chars of text";
+const KEY_DELAY_MS = 50;
+const READY_TIMEOUT_MS = 60_000;
+
+export const builderTypeField: Scenario = {
+ name: "builder-type-field",
+ description: `Type ${TEXT.length} characters, ${KEY_DELAY_MS} ms apart, into a text field of the first node in an idle 50-node workflow.`,
+ readyWhen:
+ "all 50 nodes are on the canvas and the first node's text field is focused, then network idle + 1 s",
+ windowMs: 2_000,
+ async setup(ctx) {
+ const { page } = ctx;
+ const fixture = createBuilderFixture(ctx.userID);
+ await installRoutes(page, fixture.handlers);
+ const builder = new BuildPage(page);
+ await page.goto(`/build?flowID=${fixture.graph.id}`);
+ await builder.closeTutorial();
+ const nodes = page.locator('[data-id^="custom-node-"]');
+ await nodes
+ .nth(fixture.graph.nodes.length - 1)
+ .waitFor({ state: "attached", timeout: READY_TIMEOUT_MS });
+ const field = nodes.first().locator("input:visible, textarea:visible");
+ await field
+ .first()
+ .waitFor({ state: "visible", timeout: READY_TIMEOUT_MS });
+ await field.first().click();
+ await page.keyboard.press("ControlOrMeta+A");
+ await page.keyboard.press("Backspace");
+ await settle(page);
+ return {
+ async run() {
+ await page.keyboard.type(TEXT, { delay: KEY_DELAY_MS });
+ },
+ };
+ },
+};
diff --git a/autogpt_platform/frontend/scripts/perf/scenarios/registry.ts b/autogpt_platform/frontend/scripts/perf/scenarios/registry.ts
index dc49e348e5..ee54394f64 100644
--- a/autogpt_platform/frontend/scripts/perf/scenarios/registry.ts
+++ b/autogpt_platform/frontend/scripts/perf/scenarios/registry.ts
@@ -1,8 +1,11 @@
import type { Scenario } from "../lib/scenario";
+import { builderBlockMenuSearch } from "./builder-block-menu-search";
import { builderConnectEdge } from "./builder-connect-edge";
import { builderDragRunning } from "./builder-drag-running";
+import { builderLoadGraph } from "./builder-load-graph";
import { builderRunEvents } from "./builder-run-events";
import { builderRunBeads } from "./builder-run-beads";
+import { builderTypeField } from "./builder-type-field";
import { copilotBackgroundStream } from "./copilot-background-stream";
import { copilotIdle } from "./copilot-idle";
import { copilotResizeDrag } from "./copilot-resize-drag";
@@ -31,6 +34,9 @@ export const SCENARIOS: Scenario[] = [
copilotResizeDrag,
builderRunBeads,
libraryAgentRuns,
+ builderTypeField,
+ builderBlockMenuSearch,
+ builderLoadGraph,
];
export function findScenario(name: string) {
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/__tests__/nodeStore.writes.test.ts b/autogpt_platform/frontend/src/app/(platform)/build/__tests__/nodeStore.writes.test.ts
new file mode 100644
index 0000000000..46db23824f
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/__tests__/nodeStore.writes.test.ts
@@ -0,0 +1,197 @@
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+import { useNodeStore } from "../stores/nodeStore";
+import { useHistoryStore } from "../stores/historyStore";
+import { useEdgeStore } from "../stores/edgeStore";
+import { BlockUIType } from "../components/types";
+import type {
+ CustomNode,
+ CustomNodeData,
+} from "../components/FlowEditor/nodes/CustomNode/CustomNode";
+
+function createTestNode(id: string, data: Partial<CustomNodeData> = {}) {
+ const node: CustomNode = {
+ id,
+ type: "custom",
+ position: { x: 0, y: 0 },
+ data: {
+ hardcodedValues: {},
+ title: `Node ${id}`,
+ description: "",
+ inputSchema: {},
+ outputSchema: {},
+ uiType: BlockUIType.STANDARD,
+ block_id: "test-block-id",
+ costs: [],
+ categories: [],
+ ...data,
+ },
+ };
+ return node;
+}
+
+let nodeWrites = 0;
+let unsubscribe: () => void;
+
+beforeEach(() => {
+ useNodeStore.setState({ nodes: [] });
+ useEdgeStore.setState({ edges: [] });
+ useHistoryStore.getState().clear();
+ nodeWrites = 0;
+ unsubscribe = useNodeStore.subscribe((state, prev) => {
+ if (state.nodes !== prev.nodes) nodeWrites++;
+ });
+});
+
+afterEach(() => {
+ unsubscribe();
+});
+
+async function flushHistory() {
+ await Promise.resolve();
+}
+
+describe("addNodes", () => {
+ it("adds a whole workflow in one store write", () => {
+ const nodes = Array.from({ length: 100 }, (_, i) =>
+ createTestNode(String(i)),
+ );
+
+ useNodeStore.getState().addNodes(nodes);
+
+ expect(nodeWrites).toBe(1);
+ expect(useNodeStore.getState().nodes).toEqual(nodes);
+ });
+
+ it("appends after the nodes already on the canvas, in order", () => {
+ const existing = createTestNode("a");
+ useNodeStore.getState().setNodes([existing]);
+ nodeWrites = 0;
+
+ useNodeStore
+ .getState()
+ .addNodes([createTestNode("b"), createTestNode("c")]);
+
+ expect(nodeWrites).toBe(1);
+ expect(useNodeStore.getState().nodes.map((n) => n.id)).toEqual([
+ "a",
+ "b",
+ "c",
+ ]);
+ expect(useNodeStore.getState().nodes[0]).toBe(existing);
+ });
+
+ it("writes nothing for an empty list", () => {
+ useNodeStore.getState().addNodes([]);
+
+ expect(nodeWrites).toBe(0);
+ });
+
+ it("does not add an undo entry, as before", async () => {
+ useNodeStore.getState().addNodes([createTestNode("1")]);
+ await flushHistory();
+
+ expect(useHistoryStore.getState().past).toHaveLength(1);
+ });
+
+ it("finds the added nodes by id", () => {
+ useNodeStore
+ .getState()
+ .addNodes([
+ createTestNode("1", { hardcodedValues: { a: 1 } }),
+ createTestNode("2", { hardcodedValues: { a: 2 } }),
+ ]);
+
+ expect(useNodeStore.getState().getHardCodedValues("2")).toEqual({ a: 2 });
+ });
+});
+
+describe("updateNodeData", () => {
+ it("a changed value writes once and can be undone", async () => {
+ useNodeStore.getState().setNodes([createTestNode("1")]);
+ useHistoryStore.getState().initializeHistory();
+ nodeWrites = 0;
+
+ useNodeStore
+ .getState()
+ .updateNodeData("1", { hardcodedValues: { text: "hello" } });
+ await flushHistory();
+
+ expect(nodeWrites).toBe(1);
+ expect(useNodeStore.getState().nodes[0].data.hardcodedValues).toEqual({
+ text: "hello",
+ });
+ expect(useHistoryStore.getState().canUndo()).toBe(true);
+
+ useHistoryStore.getState().undo();
+ expect(useNodeStore.getState().nodes[0].data.hardcodedValues).toEqual({});
+ });
+
+ it("an equal value writes nothing and keeps the node object", async () => {
+ const node = createTestNode("1", { hardcodedValues: { text: "same" } });
+ useNodeStore.getState().setNodes([node]);
+ useHistoryStore.getState().initializeHistory();
+ nodeWrites = 0;
+
+ useNodeStore
+ .getState()
+ .updateNodeData("1", { hardcodedValues: { text: "same" } });
+ await flushHistory();
+
+ expect(nodeWrites).toBe(0);
+ expect(useNodeStore.getState().nodes[0]).toBe(node);
+ expect(useHistoryStore.getState().canUndo()).toBe(false);
+ });
+
+ it("an unknown node writes nothing", () => {
+ useNodeStore.getState().setNodes([createTestNode("1")]);
+ nodeWrites = 0;
+
+ useNodeStore.getState().updateNodeData("missing", { title: "x" });
+
+ expect(nodeWrites).toBe(0);
+ });
+
+ it("a key the node lacks is still written when its value is undefined", () => {
+ useNodeStore.getState().setNodes([createTestNode("1")]);
+ nodeWrites = 0;
+
+ useNodeStore.getState().updateNodeData("1", { status: undefined });
+
+ expect(nodeWrites).toBe(1);
+ expect(Object.hasOwn(useNodeStore.getState().nodes[0].data, "status")).toBe(
+ true,
+ );
+ });
+
+ it("one changed key among equal ones still writes", () => {
+ useNodeStore
+ .getState()
+ .setNodes([createTestNode("1", { title: "Same", hardcodedValues: {} })]);
+ nodeWrites = 0;
+
+ useNodeStore
+ .getState()
+ .updateNodeData("1", { title: "Same", hardcodedValues: { a: 1 } });
+
+ expect(nodeWrites).toBe(1);
+ expect(useNodeStore.getState().nodes[0].data.hardcodedValues).toEqual({
+ a: 1,
+ });
+ });
+
+ it("updates every node that shares the id, as before", () => {
+ useNodeStore
+ .getState()
+ .setNodes([
+ createTestNode("1", { title: "Changed" }),
+ createTestNode("1", { title: "Old" }),
+ ]);
+
+ useNodeStore.getState().updateNodeData("1", { title: "Changed" });
+
+ expect(useNodeStore.getState().nodes.map((n) => n.data.title)).toEqual([
+ "Changed",
+ "Changed",
+ ]);
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/Flow.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/Flow.tsx
index 308b6e816a..feee3ca489 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/Flow.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/Flow.tsx
@@ -5,7 +5,7 @@ import { FloatingReviewsPanel } from "@/components/organisms/FloatingReviewsPane
import { BuilderChatPanel } from "../../BuilderChatPanel/BuilderChatPanel";
import { Background, ReactFlow } from "@xyflow/react";
import { parseAsString, useQueryStates } from "nuqs";
-import { MouseEvent, useCallback, useMemo } from "react";
+import { MouseEvent, ReactNode, useCallback, useMemo } from "react";
import { useShallow } from "zustand/react/shallow";
import { useGraphStore } from "../../../stores/graphStore";
import { useNodeStore } from "../../../stores/nodeStore";
@@ -50,37 +50,6 @@ export const Flow = () => {
},
);
- const nodes = useNodeStore(useShallow((state) => state.nodes));
- const setNodes = useNodeStore(useShallow((state) => state.setNodes));
-
- const onNodesChange = useNodeStore(
- useShallow((state) => state.onNodesChange),
- );
-
- const hasWebhookNodes = useNodeStore(
- useShallow((state) => state.hasWebhookNodes()),
- );
-
- const nodeTypes = useMemo(() => ({ custom: CustomNode }), []);
- const edgeTypes = useMemo(() => ({ custom: CustomEdge }), []);
-
- const onNodeContextMenu = useCallback((event: MouseEvent) => {
- event.preventDefault();
- }, []);
-
- const onNodeDragStop = useCallback(() => {
- const currentNodes = useNodeStore.getState().nodes;
- setNodes(
- resolveCollisions(currentNodes, {
- maxIterations: Infinity,
- overlapThreshold: 0.5,
- margin: 15,
- }),
- );
- }, [setNodes]);
-
- const { edges, onConnect, onEdgesChange } = useCustomEdge();
-
// for loading purpose
const {
onDragOver,
@@ -105,37 +74,17 @@ export const Flow = () => {
return (
<div className="flex h-full w-full dark:bg-slate-900">
<div className="relative flex-1">
- <ReactFlow
- nodes={nodes}
- onNodesChange={onNodesChange}
- nodeTypes={nodeTypes}
- edgeTypes={edgeTypes}
- edges={edges}
- onConnect={onConnect}
- onEdgesChange={onEdgesChange}
- onNodeDragStop={onNodeDragStop}
- onNodeContextMenu={onNodeContextMenu}
- maxZoom={2}
- minZoom={0.05}
+ <FlowCanvas
onDragOver={onDragOver}
onDrop={onDrop}
- nodesDraggable={!isLocked}
- nodesConnectable={!isLocked}
- elementsSelectable={!isLocked}
- deleteKeyCode={DELETE_KEY_CODES}
+ isFlowContentLoading={isFlowContentLoading}
+ isLocked={isLocked}
+ setIsLocked={setIsLocked}
+ isReadOnly={isReadOnly}
+ isGraphRunning={isGraphRunning}
>
- <Background />
- <CustomControls
- setIsLocked={setIsLocked}
- isLocked={isLocked}
- isReadOnly={isReadOnly}
- />
- <NewControlPanel isReadOnly={isReadOnly} />
- {isReadOnly && <ReadOnlyBanner />}
- {!isReadOnly &&
- (hasWebhookNodes ? <TriggerAgentBanner /> : <BuilderActions />)}
- {<GraphLoadingBox flowContentLoading={isFlowContentLoading} />}
- {isGraphRunning && <RunningBackground />}
+ {/* Created here, not in FlowCanvas, so a node or edge change re-renders
+ the canvas but hands these panels the same elements and skips them. */}
{graph && !isReadOnly && (
<FloatingSafeModeToggle
graph={graph}
@@ -143,7 +92,7 @@ export const Flow = () => {
/>
)}
<DraftRecoveryPopup isInitialLoadComplete={isInitialLoadComplete} />
- </ReactFlow>
+ </FlowCanvas>
</div>
{/* TODO: Need to update it in future - also do not send executionId as prop - rather use useQueryState inside the component */}
<FloatingReviewsPanel
@@ -156,3 +105,93 @@ export const Flow = () => {
</div>
);
};
+
+interface FlowCanvasProps
+ extends Pick<
+ ReturnType<typeof useFlow>,
+ | "onDragOver"
+ | "onDrop"
+ | "isFlowContentLoading"
+ | "isLocked"
+ | "setIsLocked"
+ | "isReadOnly"
+ > {
+ isGraphRunning: boolean;
+ children: ReactNode;
+}
+
+/**
+ * The only part of the builder that subscribes to `nodes` and `edges`, which
+ * change on every drag frame and every field edit.
+ */
+function FlowCanvas({
+ onDragOver,
+ onDrop,
+ isFlowContentLoading,
+ isLocked,
+ setIsLocked,
+ isReadOnly,
+ isGraphRunning,
+ children,
+}: FlowCanvasProps) {
+ const nodes = useNodeStore((state) => state.nodes);
+ const setNodes = useNodeStore((state) => state.setNodes);
+ const onNodesChange = useNodeStore((state) => state.onNodesChange);
+ const hasWebhookNodes = useNodeStore((state) => state.hasWebhookNodes());
+
+ const nodeTypes = useMemo(() => ({ custom: CustomNode }), []);
+ const edgeTypes = useMemo(() => ({ custom: CustomEdge }), []);
+
+ const onNodeContextMenu = useCallback((event: MouseEvent) => {
+ event.preventDefault();
+ }, []);
+
+ const onNodeDragStop = useCallback(() => {
+ const currentNodes = useNodeStore.getState().nodes;
+ setNodes(
+ resolveCollisions(currentNodes, {
+ maxIterations: Infinity,
+ overlapThreshold: 0.5,
+ margin: 15,
+ }),
+ );
+ }, [setNodes]);
+
+ const { edges, onConnect, onEdgesChange } = useCustomEdge();
+
+ return (
+ <ReactFlow
+ nodes={nodes}
+ onNodesChange={onNodesChange}
+ nodeTypes={nodeTypes}
+ edgeTypes={edgeTypes}
+ edges={edges}
+ onConnect={onConnect}
+ onEdgesChange={onEdgesChange}
+ onNodeDragStop={onNodeDragStop}
+ onNodeContextMenu={onNodeContextMenu}
+ maxZoom={2}
+ minZoom={0.05}
+ onDragOver={onDragOver}
+ onDrop={onDrop}
+ nodesDraggable={!isLocked}
+ nodesConnectable={!isLocked}
+ elementsSelectable={!isLocked}
+ deleteKeyCode={DELETE_KEY_CODES}
+ >
+ <Background />
+ <CustomControls
+ setIsLocked={setIsLocked}
+ isLocked={isLocked}
+ isReadOnly={isReadOnly}
+ />
+ <NewControlPanel isReadOnly={isReadOnly} />
+ {isReadOnly && <ReadOnlyBanner />}
+ {!isReadOnly &&
+ (hasWebhookNodes ? <TriggerAgentBanner /> : <BuilderActions />)}
+ <GraphLoadingBox flowContentLoading={isFlowContentLoading} />
+ {isGraphRunning && <RunningBackground />}
+ {children}
+ </ReactFlow>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/__tests__/Flow.isolation.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/__tests__/Flow.isolation.test.tsx
new file mode 100644
index 0000000000..a1990bfb7b
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/Flow/__tests__/Flow.isolation.test.tsx
@@ -0,0 +1,201 @@
+import { act, render, screen } from "@testing-library/react";
+import { ReactNode } from "react";
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+
+import type { CustomNode } from "../../nodes/CustomNode/CustomNode";
+import { useNodeStore } from "../../../../stores/nodeStore";
+
+// The real node store drives this test: a position or data write is what a
+// drag frame or a keystroke in a node field does.
+
+const renders = {
+ reactFlow: 0,
+ chat: 0,
+ reviews: 0,
+ safeMode: 0,
+ draftRecovery: 0,
+ controlPanel: 0,
+};
+let lastReactFlowNodes: unknown;
+
+vi.mock("../useFlow", () => ({
+ useFlow: () => ({
+ onDragOver: vi.fn(),
+ onDrop: vi.fn(),
+ isFlowContentLoading: false,
+ isInitialLoadComplete: true,
+ isLocked: false,
+ setIsLocked: vi.fn(),
+ isReadOnly: false,
+ }),
+}));
+vi.mock("../useFlowRealtime", () => ({ useFlowRealtime: vi.fn() }));
+vi.mock("../useCopyPaste", () => ({ useCopyPaste: vi.fn() }));
+vi.mock("../../edges/useCustomEdge", () => ({
+ useCustomEdge: () => ({
+ edges: [],
+ onConnect: vi.fn(),
+ onEdgesChange: vi.fn(),
+ }),
+}));
+vi.mock("../../nodes/CustomNode/CustomNode", () => ({
+ CustomNode: () => null,
+}));
+vi.mock("../../edges/CustomEdge", () => ({ default: () => null }));
+
+vi.mock("@xyflow/react", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@xyflow/react")>()),
+ ReactFlow: ({ children, nodes }: { children: ReactNode; nodes: unknown }) => {
+ renders.reactFlow++;
+ lastReactFlowNodes = nodes;
+ return <div data-testid="react-flow">{children}</div>;
+ },
+ Background: () => null,
+}));
+
+vi.mock("@/app/api/__generated__/endpoints/graphs/graphs", () => ({
+ useGetV1GetSpecificGraph: () => ({ data: { id: "graph-1" } }),
+}));
+vi.mock("nuqs", () => ({
+ parseAsString: {},
+ useQueryStates: () => [{ flowID: "graph-1", flowExecutionID: null }, vi.fn()],
+}));
+
+vi.mock("../../../NewControlPanel/NewControlPanel", () => ({
+ default: () => {
+ renders.controlPanel++;
+ return null;
+ },
+}));
+vi.mock("../../../BuilderActions/BuilderActions", () => ({
+ BuilderActions: () => null,
+}));
+vi.mock("../components/CustomControl", () => ({
+ CustomControls: () => null,
+}));
+vi.mock("../components/GraphLoadingBox", () => ({
+ GraphLoadingBox: () => null,
+}));
+vi.mock("../../../FloatingSafeModeToogle", () => ({
+ FloatingSafeModeToggle: () => {
+ renders.safeMode++;
+ return <div data-testid="safe-mode-toggle" />;
+ },
+}));
+vi.mock("../../../DraftRecoveryDialog/DraftRecoveryPopup", () => ({
+ DraftRecoveryPopup: () => {
+ renders.draftRecovery++;
+ return <div data-testid="draft-recovery" />;
+ },
+}));
+vi.mock("../../../BuilderChatPanel/BuilderChatPanel", () => ({
+ BuilderChatPanel: () => {
+ renders.chat++;
+ return <div data-testid="builder-chat" />;
+ },
+}));
+vi.mock(
+ "@/components/organisms/FloatingReviewsPanel/FloatingReviewsPanel",
+ () => ({
+ FloatingReviewsPanel: () => {
+ renders.reviews++;
+ return <div data-testid="reviews-panel" />;
+ },
+ }),
+);
+
+import { Flow } from "../Flow";
+
+function makeNode(id: string, x: number): CustomNode {
+ return {
+ id,
+ type: "custom",
+ position: { x, y: 0 },
+ data: {
+ title: `Node ${id}`,
+ block_id: "block",
+ hardcodedValues: { text: "" },
+ inputSchema: { type: "object", properties: {} },
+ outputSchema: { type: "object", properties: {} },
+ description: "",
+ uiType: "Standard",
+ costs: [],
+ categories: [],
+ },
+ } as unknown as CustomNode;
+}
+
+beforeEach(() => {
+ for (const key of Object.keys(renders) as (keyof typeof renders)[]) {
+ renders[key] = 0;
+ }
+ useNodeStore.getState().setNodes([makeNode("1", 0), makeNode("2", 300)]);
+});
+
+afterEach(() => {
+ useNodeStore.getState().setNodes([]);
+});
+
+describe("Flow canvas isolation", () => {
+ test("a drag frame re-renders the canvas but not the panels beside it", () => {
+ render(<Flow />);
+ expect(screen.getByTestId("builder-chat")).toBeDefined();
+ expect(screen.getByTestId("reviews-panel")).toBeDefined();
+ expect(screen.getByTestId("safe-mode-toggle")).toBeDefined();
+ expect(screen.getByTestId("draft-recovery")).toBeDefined();
+ const mounted = { ...renders };
+
+ for (let frame = 1; frame <= 5; frame++) {
+ act(() => {
+ useNodeStore.getState().onNodesChange([
+ {
+ type: "position",
+ id: "1",
+ position: { x: frame * 10, y: 0 },
+ dragging: true,
+ },
+ ]);
+ });
+ }
+
+ expect(renders.reactFlow).toBe(mounted.reactFlow + 5);
+ expect(lastReactFlowNodes).toBe(useNodeStore.getState().nodes);
+ expect(renders.chat).toBe(mounted.chat);
+ expect(renders.reviews).toBe(mounted.reviews);
+ expect(renders.safeMode).toBe(mounted.safeMode);
+ expect(renders.draftRecovery).toBe(mounted.draftRecovery);
+ });
+
+ test("a field edit re-renders the canvas but not the panels beside it", () => {
+ render(<Flow />);
+ const mounted = { ...renders };
+
+ act(() => {
+ useNodeStore
+ .getState()
+ .updateNodeData("1", { hardcodedValues: { text: "hello" } });
+ });
+
+ expect(renders.reactFlow).toBe(mounted.reactFlow + 1);
+ expect(renders.chat).toBe(mounted.chat);
+ expect(renders.reviews).toBe(mounted.reviews);
+ });
+
+ test("controls inside the canvas still re-render with it", () => {
+ render(<Flow />);
+ const mounted = renders.controlPanel;
+
+ act(() => {
+ useNodeStore.getState().onNodesChange([
+ {
+ type: "position",
+ id: "2",
+ position: { x: 50, y: 50 },
+ dragging: true,
+ },
+ ]);
+ });
+
+ expect(renders.controlPanel).toBe(mounted + 1);
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/Block.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/Block.tsx
index 40bf3ee468..396e13c0dd 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/Block.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/Block.tsx
@@ -1,7 +1,7 @@
import { Button } from "@/components/__legacy__/ui/button";
import { Skeleton } from "@/components/__legacy__/ui/skeleton";
import { beautifyString, cn } from "@/lib/utils";
-import React, { ButtonHTMLAttributes, useState } from "react";
+import React, { ButtonHTMLAttributes, memo, useState } from "react";
import { highlightText } from "./helpers";
import { BlockInfo } from "@/app/api/__generated__/models/blockInfo";
import { useControlPanelStore } from "../../../stores/controlPanelStore";
@@ -23,18 +23,14 @@ interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
blockData: BlockInfo;
}
-interface BlockComponent extends React.FC<Props> {
- Skeleton: React.FC<{ className?: string }>;
-}
-
-export const Block: BlockComponent = ({
+function BlockCard({
title,
description,
highlightedText,
className,
blockData,
...rest
-}) => {
+}: Props) {
const setBlockMenuOpen = useControlPanelStore(
(state) => state.setBlockMenuOpen,
);
@@ -173,7 +169,7 @@ export const Block: BlockComponent = ({
)}
</>
);
-};
+}
const BlockSkeleton = () => {
return (
@@ -187,4 +183,8 @@ const BlockSkeleton = () => {
);
};
-Block.Skeleton = BlockSkeleton;
+// Memoised: a list re-renders for its own reasons (a new page arriving, a
+// filter count updating) without the rows' props changing.
+export const Block = Object.assign(memo(BlockCard), {
+ Skeleton: BlockSkeleton,
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuContent/BlockMenuContent.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuContent/BlockMenuContent.tsx
index 5ae1ff38e0..7da46918b4 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuContent/BlockMenuContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuContent/BlockMenuContent.tsx
@@ -7,7 +7,7 @@ import { BlockMenuSearch } from "../BlockMenuSearch/BlockMenuSearch";
import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
export const BlockMenuContent = () => {
- const { searchQuery } = useBlockMenuStore();
+ const searchQuery = useBlockMenuStore((state) => state.searchQuery);
return (
<div className="flex h-full w-full flex-col">
<BlockMenuSearchBar />
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuDefaultContent/BlockMenuDefaultContent.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuDefaultContent/BlockMenuDefaultContent.tsx
index ad27766d04..cd9a0b0e91 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuDefaultContent/BlockMenuDefaultContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuDefaultContent/BlockMenuDefaultContent.tsx
@@ -9,7 +9,7 @@ import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
import { DefaultStateType } from "../types";
export const BlockMenuDefaultContent = () => {
- const { defaultState } = useBlockMenuStore();
+ const defaultState = useBlockMenuStore((state) => state.defaultState);
return (
<div className="h-full flex-1 overflow-hidden">
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/BlockMenuFilters.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/BlockMenuFilters.tsx
index 7976832bb1..b2ea798974 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/BlockMenuFilters.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuFilters/BlockMenuFilters.tsx
@@ -1,4 +1,5 @@
import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore";
+import { useShallow } from "zustand/react/shallow";
import { FilterChip } from "../FilterChip";
import { categories } from "./constants";
import { FilterSheet } from "../FilterSheet/FilterSheet";
@@ -13,7 +14,17 @@ export const BlockMenuFilters = () => {
creators,
addCreator,
removeCreator,
- } = useBlockMenuStore();
+ } = useBlockMenuStore(
+ useShallow((state) => ({
+ filters: state.filters,
+ addFilter: state.addFilter,
+ removeFilter: state.removeFilter,
+ categoryCounts: state.categoryCounts,
+ creators: state.creators,
+ addCreator: state.addCreator,
+ removeCreator: state.removeCreator,
+ })),
+ );
const handleFilterClick = (filter: CategoryKey) => {
if (filters.includes(filter)) {
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchBar/useBlockMenuSearchBar.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchBar/useBlockMenuSearchBar.ts
index e98d240215..dd922fdc3d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchBar/useBlockMenuSearchBar.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchBar/useBlockMenuSearchBar.ts
@@ -1,6 +1,7 @@
import debounce from "lodash/debounce";
import { useCallback, useEffect, useRef, useState } from "react";
import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
+import { useShallow } from "zustand/react/shallow";
import { getQueryClient } from "@/lib/react-query/queryClient";
import { getGetV2GetBuilderSuggestionsQueryKey } from "@/app/api/__generated__/endpoints/default/default";
@@ -9,7 +10,13 @@ const SEARCH_DEBOUNCE_MS = 300;
export const useBlockMenuSearchBar = () => {
const inputRef = useRef<HTMLInputElement>(null);
const [localQuery, setLocalQuery] = useState("");
- const { setSearchQuery, setSearchId, searchQuery } = useBlockMenuStore();
+ const { setSearchQuery, setSearchId, searchQuery } = useBlockMenuStore(
+ useShallow((state) => ({
+ setSearchQuery: state.setSearchQuery,
+ setSearchId: state.setSearchId,
+ searchQuery: state.searchQuery,
+ })),
+ );
const queryClient = getQueryClient();
const clearSearchSession = useCallback(() => {
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/BlockMenuSearchContent.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/BlockMenuSearchContent.tsx
index 7229c44ed7..9bc4d2f217 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/BlockMenuSearchContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/BlockMenuSearchContent.tsx
@@ -1,7 +1,7 @@
import { SearchResponseItemsItem } from "@/app/api/__generated__/models/searchResponseItemsItem";
import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";
import { InfiniteScroll } from "@/components/contextual/InfiniteScroll/InfiniteScroll";
-import { getSearchItemType } from "./helper";
+import { getSearchItemKeys, getSearchItemType } from "./helper";
import { MarketplaceAgentBlock } from "../MarketplaceAgentBlock";
import { Block } from "../Block";
import { UGCAgentBlock } from "../UGCAgentBlock";
@@ -24,7 +24,7 @@ export const BlockMenuSearchContent = () => {
addingMarketplaceAgentSlug,
} = useBlockMenuSearchContent();
- const { searchQuery } = useBlockMenuStore();
+ const searchQuery = useBlockMenuStore((state) => state.searchQuery);
if (searchLoading) {
return (
@@ -43,6 +43,8 @@ export const BlockMenuSearchContent = () => {
return <NoSearchResult />;
}
+ const keys = getSearchItemKeys(searchResults);
+
return (
<InfiniteScroll
isFetchingNextPage={isFetchingNextPage}
@@ -58,7 +60,7 @@ export const BlockMenuSearchContent = () => {
case "store_agent":
return (
<MarketplaceAgentBlock
- key={index}
+ key={keys[index]}
slug={data.slug}
highlightedText={searchQuery}
title={data.agent_name}
@@ -77,7 +79,7 @@ export const BlockMenuSearchContent = () => {
case "block":
return (
<Block
- key={index}
+ key={keys[index]}
title={data.name}
highlightedText={searchQuery}
description={data.description}
@@ -88,7 +90,7 @@ export const BlockMenuSearchContent = () => {
case "library_agent":
return (
<UGCAgentBlock
- key={index}
+ key={keys[index]}
title={data.name}
highlightedText={searchQuery}
image_url={data.image_url}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/helper.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/helper.ts
index 830b75ad4e..2e908c87f7 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/helper.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/helper.ts
@@ -23,3 +23,21 @@ export const getSearchItemType = (
throw new Error("Unknown item type");
};
+
+/**
+ * A React key per search result that stays with the item when the list
+ * changes. Results of different types can share an id, and a later page can
+ * repeat an earlier item, so the type is part of the key and a repeat falls
+ * back to its position.
+ */
+export function getSearchItemKeys(items: SearchResponseItemsItem[]) {
+ const seen = new Set<string>();
+ return items.map((item, index) => {
+ const { type, data } = getSearchItemType(item);
+ const id = type === "store_agent" ? data.slug : data.id;
+ const key = `${type}-${id}`;
+ if (!id || seen.has(key)) return `${key}-${index}`;
+ seen.add(key);
+ return key;
+ });
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/useBlockMenuSearchContent.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/useBlockMenuSearchContent.tsx
index 0a14665518..97ce365f4c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/useBlockMenuSearchContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSearchContent/useBlockMenuSearchContent.tsx
@@ -1,5 +1,6 @@
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useMemo, useState } from "react";
import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore";
+import { useShallow } from "zustand/react/shallow";
import { useAddAgentToBuilder } from "../hooks/useAddAgentToBuilder";
import {
getPaginationNextPageNumber,
@@ -34,7 +35,17 @@ export const useBlockMenuSearchContent = () => {
setCreatorsList,
creators,
setCategoryCounts,
- } = useBlockMenuStore();
+ } = useBlockMenuStore(
+ useShallow((state) => ({
+ searchQuery: state.searchQuery,
+ searchId: state.searchId,
+ setSearchId: state.setSearchId,
+ filters: state.filters,
+ setCreatorsList: state.setCreatorsList,
+ creators: state.creators,
+ setCategoryCounts: state.setCategoryCounts,
+ })),
+ );
const { toast } = useToast();
const { addAgentToBuilder, addLibraryAgentToBuilder } =
@@ -133,9 +144,10 @@ export const useBlockMenuSearchContent = () => {
}
}, [resetSearchSession, searchId, searchQuery]);
- const searchResults = searchQueryData
- ? unpaginate(searchQueryData, "items")
- : [];
+ const searchResults = useMemo(
+ () => (searchQueryData ? unpaginate(searchQueryData, "items") : []),
+ [searchQueryData],
+ );
const handleAddLibraryAgent = async (agent: LibraryAgent) => {
setAddingLibraryAgentId(agent.id);
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSidebar/BlockMenuSidebar.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSidebar/BlockMenuSidebar.tsx
index 9508956df5..312aaa012c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSidebar/BlockMenuSidebar.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSidebar/BlockMenuSidebar.tsx
@@ -9,7 +9,7 @@ import { DefaultStateType } from "../types";
export const BlockMenuSidebar = () => {
const { data, setDefaultState, defaultState, isLoading, isError, error } =
useBlockMenuSidebar();
- const { setIntegration } = useBlockMenuStore();
+ const setIntegration = useBlockMenuStore((state) => state.setIntegration);
if (isLoading) {
return (
<div className="w-fit space-y-2 px-4 pt-4">
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSidebar/useBlockMenuSidebar.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSidebar/useBlockMenuSidebar.ts
index 8c9201ab2b..d5733f4f88 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSidebar/useBlockMenuSidebar.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/BlockMenuSidebar/useBlockMenuSidebar.ts
@@ -1,9 +1,15 @@
import { useGetV2GetBuilderItemCounts } from "@/app/api/__generated__/endpoints/default/default";
import { CountResponse } from "@/app/api/__generated__/models/countResponse";
import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
+import { useShallow } from "zustand/react/shallow";
export const useBlockMenuSidebar = () => {
- const { defaultState, setDefaultState } = useBlockMenuStore();
+ const { defaultState, setDefaultState } = useBlockMenuStore(
+ useShallow((state) => ({
+ defaultState: state.defaultState,
+ setDefaultState: state.setDefaultState,
+ })),
+ );
const { data, isLoading, isError, error } = useGetV2GetBuilderItemCounts({
query: {
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/useFilterSheet.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/useFilterSheet.ts
index 63e19ade7c..10f157a63d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/useFilterSheet.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/FilterSheet/useFilterSheet.ts
@@ -1,11 +1,20 @@
import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore";
+import { useShallow } from "zustand/react/shallow";
import { useState } from "react";
import { INITIAL_CREATORS_TO_SHOW } from "./constant";
import { CategoryKey } from "../BlockMenuFilters/types";
export const useFilterSheet = () => {
const { filters, creators_list, creators, setFilters, setCreators } =
- useBlockMenuStore();
+ useBlockMenuStore(
+ useShallow((state) => ({
+ filters: state.filters,
+ creators_list: state.creators_list,
+ creators: state.creators,
+ setFilters: state.setFilters,
+ setCreators: state.setCreators,
+ })),
+ );
const [isOpen, setIsOpen] = useState(false);
const [localCategories, setLocalCategories] =
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationBlocks/IntegrationBlocks.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationBlocks/IntegrationBlocks.tsx
index 1934b568fa..6fcbcda9f2 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationBlocks/IntegrationBlocks.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationBlocks/IntegrationBlocks.tsx
@@ -6,9 +6,15 @@ import { useIntegrationBlocks } from "./useIntegrationBlocks";
import { ErrorCard } from "@/components/molecules/ErrorCard/ErrorCard";
import { InfiniteScroll } from "@/components/contextual/InfiniteScroll/InfiniteScroll";
import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
+import { useShallow } from "zustand/react/shallow";
export const IntegrationBlocks = () => {
- const { integration, setIntegration } = useBlockMenuStore();
+ const { integration, setIntegration } = useBlockMenuStore(
+ useShallow((state) => ({
+ integration: state.integration,
+ setIntegration: state.setIntegration,
+ })),
+ );
const {
allBlocks,
status,
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationBlocks/useIntegrationBlocks.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationBlocks/useIntegrationBlocks.ts
index c6dcd61e36..c36ec600cf 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationBlocks/useIntegrationBlocks.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationBlocks/useIntegrationBlocks.ts
@@ -9,7 +9,7 @@ import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore"
const PAGE_SIZE = 10;
export const useIntegrationBlocks = () => {
- const { integration } = useBlockMenuStore();
+ const integration = useBlockMenuStore((state) => state.integration);
const {
data: blocksQueryData,
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationsContent/IntegrationsContent.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationsContent/IntegrationsContent.tsx
index 00cbd8723c..7c6c0fa326 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationsContent/IntegrationsContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/IntegrationsContent/IntegrationsContent.tsx
@@ -6,7 +6,7 @@ import { cn } from "@/lib/utils";
import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
export const IntegrationsContent = () => {
- const { integration } = useBlockMenuStore();
+ const integration = useBlockMenuStore((state) => state.integration);
if (!integration) {
return <PaginatedIntegrationList />;
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/PaginatedIntegrationList/PaginatedIntegrationList.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/PaginatedIntegrationList/PaginatedIntegrationList.tsx
index 04e604fd9e..f50972a8b0 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/PaginatedIntegrationList/PaginatedIntegrationList.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/PaginatedIntegrationList/PaginatedIntegrationList.tsx
@@ -7,7 +7,7 @@ import { blockMenuContainerStyle } from "../style";
import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
export const PaginatedIntegrationList = () => {
- const { setIntegration } = useBlockMenuStore();
+ const setIntegration = useBlockMenuStore((state) => state.setIntegration);
const {
allProviders: providers,
providersLoading,
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/SuggestionContent/SuggestionContent.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/SuggestionContent/SuggestionContent.tsx
index b00714f4ca..6198853b0d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/SuggestionContent/SuggestionContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/SuggestionContent/SuggestionContent.tsx
@@ -5,13 +5,21 @@ import { useSuggestionContent } from "./useSuggestionContent";
import { ErrorCard } from "@/components/molecules/ErrorCard/ErrorCard";
import { blockMenuContainerStyle } from "../style";
import { useBlockMenuStore } from "../../../../stores/blockMenuStore";
+import { useShallow } from "zustand/react/shallow";
import { DefaultStateType } from "../types";
import { SearchHistoryChip } from "../SearchHistoryChip";
import { HorizontalScroll } from "../HorizontalScroll";
export const SuggestionContent = () => {
const { setIntegration, setDefaultState, setSearchQuery, setSearchId } =
- useBlockMenuStore();
+ useBlockMenuStore(
+ useShallow((state) => ({
+ setIntegration: state.setIntegration,
+ setDefaultState: state.setDefaultState,
+ setSearchQuery: state.setSearchQuery,
+ setSearchId: state.setSearchId,
+ })),
+ );
const { data, isLoading, isError, error, refetch } = useSuggestionContent();
const suggestions = data?.suggestions;
const hasRecentSearches = (suggestions?.recent_searches?.length ?? 0) > 0;
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/__tests__/BlockMenuNavigation.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/__tests__/BlockMenuNavigation.test.tsx
new file mode 100644
index 0000000000..53ba173825
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/__tests__/BlockMenuNavigation.test.tsx
@@ -0,0 +1,154 @@
+import {
+ getGetV2GetBuilderBlocksMockHandler,
+ getGetV2GetBuilderIntegrationProvidersMockHandler,
+ getGetV2GetBuilderItemCountsMockHandler,
+ getGetV2GetBuilderSuggestionsMockHandler,
+} from "@/app/api/__generated__/endpoints/default/default.msw";
+import type { BlockInfo } from "@/app/api/__generated__/models/blockInfo";
+import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore";
+import { server } from "@/mocks/mock-server";
+import {
+ act,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@/tests/integrations/test-utils";
+import { beforeEach, describe, expect, test, vi } from "vitest";
+
+import { BlockMenuDefault } from "../BlockMenuDefault/BlockMenuDefault";
+import { BlockMenuFilters } from "../BlockMenuFilters/BlockMenuFilters";
+import { DefaultStateType } from "../types";
+
+// Every block-menu view reads the store through its own selector; these tests
+// drive the views through the store and the sidebar to check they still follow
+// it.
+
+vi.mock("../hooks/useAddBlockToBuilder", () => ({
+ useAddBlockToBuilder: () => ({ addBlockWithPlacement: vi.fn() }),
+}));
+
+const pagination = {
+ total_items: 1,
+ total_pages: 1,
+ current_page: 1,
+ page_size: 10,
+};
+
+const githubBlock = {
+ id: "github-block",
+ name: "Github Read Issue Block",
+ description: "Reads one GitHub issue",
+ inputSchema: {},
+ outputSchema: {},
+ costs: [],
+ categories: [],
+ contributors: [],
+ staticOutput: false,
+ uiType: "Standard",
+} as unknown as BlockInfo;
+
+function findMenuItem(type: string) {
+ return waitFor(() => {
+ const item = document.querySelector(`[data-id="menu-item-${type}"]`);
+ if (!item) throw new Error(`menu item ${type} not rendered`);
+ return item;
+ });
+}
+
+beforeEach(() => {
+ server.use(
+ getGetV2GetBuilderItemCountsMockHandler({
+ all_blocks: 12,
+ input_blocks: 2,
+ action_blocks: 8,
+ output_blocks: 2,
+ integrations: 1,
+ marketplace_agents: 0,
+ my_agents: 0,
+ }),
+ getGetV2GetBuilderSuggestionsMockHandler({
+ recent_searches: [],
+ providers: [],
+ top_blocks: [],
+ }),
+ getGetV2GetBuilderIntegrationProvidersMockHandler({
+ providers: [
+ { name: "github", description: "GitHub blocks", integration_count: 1 },
+ ],
+ pagination,
+ }),
+ getGetV2GetBuilderBlocksMockHandler({ blocks: [githubBlock], pagination }),
+ );
+ useBlockMenuStore.setState({
+ searchQuery: "",
+ searchId: undefined,
+ defaultState: DefaultStateType.SUGGESTION,
+ integration: undefined,
+ filters: [],
+ creators: [],
+ creators_list: [],
+ categoryCounts: {
+ blocks: 0,
+ integrations: 0,
+ marketplace_agents: 0,
+ my_agents: 0,
+ },
+ });
+});
+
+describe("block menu default view", () => {
+ test("the sidebar opens integrations, one integration's blocks, and back", async () => {
+ render(<BlockMenuDefault />);
+
+ fireEvent.click(await findMenuItem("integrations"));
+ expect(useBlockMenuStore.getState().defaultState).toBe(
+ DefaultStateType.INTEGRATIONS,
+ );
+
+ fireEvent.click(await screen.findByText("GitHub blocks"));
+ expect(useBlockMenuStore.getState().integration).toBe("github");
+ expect(await screen.findByText("Reads one GitHub issue")).toBeDefined();
+
+ fireEvent.click(screen.getByRole("button", { name: "Integrations" }));
+ expect(useBlockMenuStore.getState().integration).toBeUndefined();
+ expect(await screen.findByText("GitHub blocks")).toBeDefined();
+ });
+
+ test("a store change made elsewhere switches the view", async () => {
+ render(<BlockMenuDefault />);
+ await findMenuItem("integrations");
+
+ act(() => {
+ useBlockMenuStore
+ .getState()
+ .setDefaultState(DefaultStateType.INTEGRATIONS);
+ useBlockMenuStore.getState().setIntegration("github");
+ });
+
+ expect(await screen.findByText("Reads one GitHub issue")).toBeDefined();
+ });
+});
+
+describe("block menu filters", () => {
+ test("chips toggle filters and show the latest counts", async () => {
+ render(<BlockMenuFilters />);
+
+ act(() => {
+ useBlockMenuStore.getState().setCategoryCounts({
+ blocks: 7,
+ integrations: 3,
+ marketplace_agents: 0,
+ my_agents: 0,
+ });
+ });
+ fireEvent.mouseEnter(screen.getByRole("button", { name: /Blocks/ }));
+ expect(await screen.findByText("7")).toBeDefined();
+
+ fireEvent.click(screen.getByText("Blocks"));
+ expect(useBlockMenuStore.getState().filters).toEqual(["blocks"]);
+
+ fireEvent.click(screen.getByText("Blocks"));
+ expect(useBlockMenuStore.getState().filters).toEqual([]);
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/__tests__/BlockMenuSearchContent.rerender.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/__tests__/BlockMenuSearchContent.rerender.test.tsx
new file mode 100644
index 0000000000..4acd93bca5
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/__tests__/BlockMenuSearchContent.rerender.test.tsx
@@ -0,0 +1,142 @@
+import { getGetV2BuilderSearchMockHandler } from "@/app/api/__generated__/endpoints/store/store.msw";
+import type { BlockInfo } from "@/app/api/__generated__/models/blockInfo";
+import type { SearchResponse } from "@/app/api/__generated__/models/searchResponse";
+import { useBlockMenuStore } from "@/app/(platform)/build/stores/blockMenuStore";
+import { server } from "@/mocks/mock-server";
+import { act, render, waitFor } from "@/tests/integrations/test-utils";
+import { beforeEach, describe, expect, test, vi } from "vitest";
+
+import { BlockMenuSearchContent } from "../BlockMenuSearchContent/BlockMenuSearchContent";
+import { getSearchItemKeys } from "../BlockMenuSearchContent/helper";
+import { highlightText } from "../helpers";
+
+vi.mock("../helpers", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("../helpers")>();
+ return { ...actual, highlightText: vi.fn(actual.highlightText) };
+});
+
+vi.mock("../hooks/useAddBlockToBuilder", () => ({
+ useAddBlockToBuilder: () => ({ addBlockWithPlacement: vi.fn() }),
+}));
+
+function findRow(id: string) {
+ return waitFor(() => {
+ const row = document.querySelector(`[data-id="block-card-${id}"]`);
+ if (!row) throw new Error(`row ${id} not rendered`);
+ return row;
+ });
+}
+
+function makeBlock(id: string, name: string): BlockInfo {
+ return {
+ id,
+ name,
+ description: `${name} description`,
+ inputSchema: {},
+ outputSchema: {},
+ costs: [],
+ categories: [],
+ contributors: [],
+ staticOutput: false,
+ uiType: "Standard",
+ } as unknown as BlockInfo;
+}
+
+const blocks = [
+ makeBlock("block-a", "Calculator Block"),
+ makeBlock("block-b", "Calendar Block"),
+ makeBlock("block-c", "Call Webhook Block"),
+];
+
+const searchResponse: SearchResponse = {
+ items: blocks,
+ search_id: "search-1",
+ total_items: {
+ blocks: 3,
+ integrations: 0,
+ marketplace_agents: 0,
+ my_agents: 0,
+ },
+ pagination: {
+ total_items: 3,
+ total_pages: 1,
+ current_page: 1,
+ page_size: 8,
+ },
+} as SearchResponse;
+
+beforeEach(() => {
+ server.use(getGetV2BuilderSearchMockHandler(searchResponse));
+ useBlockMenuStore.setState({
+ searchQuery: "cal",
+ searchId: undefined,
+ filters: [],
+ creators: [],
+ creators_list: [],
+ });
+ vi.mocked(highlightText).mockClear();
+});
+
+describe("BlockMenuSearchContent", () => {
+ test("filter counts and the creator list arriving do not re-render the result rows", async () => {
+ render(<BlockMenuSearchContent />);
+
+ await findRow("blocka");
+ expect(await findRow("blockc")).toBeDefined();
+
+ // Let the effects that copy the response into the store run first.
+ await act(async () => {});
+ const callsAfterLoad = vi.mocked(highlightText).mock.calls.length;
+ expect(callsAfterLoad).toBeGreaterThan(0);
+
+ act(() => {
+ useBlockMenuStore.getState().setCategoryCounts({
+ blocks: 9,
+ integrations: 1,
+ marketplace_agents: 2,
+ my_agents: 3,
+ });
+ useBlockMenuStore.getState().setCreatorsList([]);
+ });
+
+ expect(vi.mocked(highlightText).mock.calls.length).toBe(callsAfterLoad);
+ expect((await findRow("blockb")).textContent).toContain("Calendar");
+ });
+
+ test("a new search query still re-renders the rows with the new highlight", async () => {
+ render(<BlockMenuSearchContent />);
+ await findRow("blocka");
+ await act(async () => {});
+ vi.mocked(highlightText).mockClear();
+
+ act(() => {
+ useBlockMenuStore.getState().setSearchQuery("calc");
+ });
+
+ await waitFor(() =>
+ expect(vi.mocked(highlightText)).toHaveBeenCalledWith(
+ "Calculator",
+ "calc",
+ ),
+ );
+ expect((await findRow("blocka")).querySelector("mark")?.textContent).toBe(
+ "Calc",
+ );
+ });
+});
+
+describe("getSearchItemKeys", () => {
+ test("keys each result by type and id, and keeps repeats unique", () => {
+ const keys = getSearchItemKeys([blocks[0], blocks[1], blocks[0]]);
+
+ expect(keys).toEqual(["block-block-a", "block-block-b", "block-block-a-2"]);
+ expect(new Set(keys).size).toBe(3);
+ });
+
+ test("a result keeps its key when an earlier one leaves the list", () => {
+ const before = getSearchItemKeys(blocks);
+ const after = getSearchItemKeys(blocks.slice(1));
+
+ expect(after).toEqual(before.slice(1));
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/stores/nodeStore.ts b/autogpt_platform/frontend/src/app/(platform)/build/stores/nodeStore.ts
index a96e66d8dc..40d5371967 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/stores/nodeStore.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/stores/nodeStore.ts
@@ -1,4 +1,5 @@
import { create } from "zustand";
+import isEqual from "lodash/isEqual";
import { NodeChange, XYPosition, applyNodeChanges } from "@xyflow/react";
import { CustomNode } from "../components/FlowEditor/nodes/CustomNode/CustomNode";
import { CustomEdge } from "../components/FlowEditor/edges/CustomEdge";
@@ -263,6 +264,13 @@ export const useNodeStore = create<NodeStore>((set, get) => ({
edges: useEdgeStore.getState().edges,
};
+ // A write that changes nothing would still hand every subscriber a new
+ // nodes array and re-render the canvas, and could never add an undo entry.
+ const changesSomething = prevState.nodes.some(
+ (n) => n.id === nodeId && !hasNodeData(n.data, data),
+ );
+ if (!changesSomething) return;
+
set((state) => ({
nodes: state.nodes.map((n) =>
n.id === nodeId ? { ...n, data: { ...n.data, ...data } } : n,
@@ -288,9 +296,12 @@ export const useNodeStore = create<NodeStore>((set, get) => ({
getShowAdvanced: (nodeId: string) =>
get().nodeAdvancedStates[nodeId] || false,
addNodes: (nodes: CustomNode[]) => {
- nodes.forEach((node) => {
- get().addNode(node);
- });
+ // One write for the whole batch: a write per node made every subscriber
+ // run once per node while a saved workflow loads.
+ if (nodes.length === 0) return;
+ set((state) => ({
+ nodes: [...state.nodes, ...nodes],
+ }));
},
getHardCodedValues: (nodeId: string) => {
return findNodeById(get().nodes, nodeId)?.data?.hardcodedValues || {};
@@ -584,6 +595,20 @@ export const useNodeStore = create<NodeStore>((set, get) => ({
},
}));
+/**
+ * Whether `data` already holds every value in `update`. A key the node does
+ * not have counts as a change even when its new value is `undefined`, because
+ * adding it still changes what the undo history compares.
+ */
+function hasNodeData(
+ data: CustomNode["data"],
+ update: Partial<CustomNode["data"]>,
+) {
+ return (Object.keys(update) as (keyof CustomNode["data"])[]).every(
+ (key) => Object.hasOwn(data, key) && isEqual(data[key], update[key]),
+ );
+}
+
const nodeIndexes = new WeakMap<CustomNode[], Map<string, CustomNode>>();
/**
diff --git a/docs/engineering/frontend-perf-baseline.md b/docs/engineering/frontend-perf-baseline.md
index 69fee1f1b5..bda4e120fe 100644
--- a/docs/engineering/frontend-perf-baseline.md
+++ b/docs/engineering/frontend-perf-baseline.md
@@ -726,3 +726,147 @@ Added with SECRT-3010 and measured on `dev` at `ede2df2ae`, before that change.
| `Dialog props:controlled,styling,children` | 328 |
| `MenuProvider props:scope,children` | 302 |
| `Primitive.div props:children` | 224 |
+
+## builder-type-field · baseline — median of 3 runs
+
+Added with SECRT-3012: `dev` app code at `8eb406275` on a similar 16 GB cloud sandbox, Chrome 141 (`--channel chrome`), 1 warm-up and 3 saved runs. On this code every keystroke re-renders `<Flow>` and the panels beside the canvas (`BuilderChatPanel`, `FloatingReviewsPanel`, `DraftRecoveryPopup`, `FloatingSafeModeToggle`): 20 renders each.
+
+| metric | median | range | spread |
+| --- | --- | --- | --- |
+| commits | 120 | 120 – 120 | 0.0% |
+| total renders | 9,680 | 9,680 – 9,680 | 0.0% |
+| renders per commit | 80.7 | 80.7 – 80.7 | 0.0% |
+| max renders in one commit | 207 | 207 – 207 | 0.0% |
+| script time (ms) | 826 | 702 – 929 | 27.5% |
+| task time (ms) | 1,013 | 862 – 1,114 | 24.9% |
+| layout time (ms) | 16 | 14 – 17 | 16.1% |
+| style recalc time (ms) | 2 | 2 – 2 | 10.0% |
+| long tasks (≥ 50 ms) | 4 | 0 – 7 | 175.0% |
+| long task total (ms) | 257 | 0 – 500 | 194.2% |
+| heap used after GC (MB) | 82.1 | 82.0 – 82.1 | 0.2% |
+
+**Top components (median renders)**
+
+| name | renders |
+| --- | --- |
+| `Primitive.div` | 440 |
+| `Tooltip` | 360 |
+| `TooltipContent` | 360 |
+| `TooltipProvider` | 340 |
+| `Presence` | 320 |
+| `HugeiconsIcon` | 300 |
+| `Icon` | 300 |
+| `SelectItem` | 280 |
+| `Popper` | 260 |
+| `PopperAnchor` | 260 |
+
+**Top render causes (median renders)**
+
+| name | renders |
+| --- | --- |
+| `Tooltip props:children` | 360 |
+| `TooltipProvider props:children` | 340 |
+| `Presence props:children` | 320 |
+| `HugeiconsIcon parent-same-props<-Icon` | 280 |
+| `SelectItem props:onMouseDown,children` | 280 |
+| `Primitive.div props:children` | 260 |
+| `Primitive.div.Slot props:children` | 260 |
+| `Primitive.div.SlotClone props:children` | 260 |
+| `Popper props:children` | 220 |
+| `PopperAnchor props:children` | 220 |
+
+## builder-block-menu-search · baseline — median of 3 runs
+
+Added with SECRT-3012: `dev` app code at `8eb406275`, same machine and settings. Results come from the real backend's block search, so the counts depend on the blocks the backend has. On this code each new page of results re-renders every `Block` row already in the list (`Block parent-same-props<-InfiniteScroll`). One run in three loaded one page fewer within the window (1,461 renders).
+
+| metric | median | range | spread |
+| --- | --- | --- | --- |
+| commits | 64 | 59 – 64 | 7.8% |
+| total renders | 1,843 | 1,461 – 1,843 | 20.7% |
+| renders per commit | 28.8 | 24.8 – 28.8 | 14.0% |
+| max renders in one commit | 211 | 179 – 211 | 15.2% |
+| script time (ms) | 268 | 195 – 274 | 29.4% |
+| task time (ms) | 937 | 810 – 992 | 19.5% |
+| layout time (ms) | 11 | 9 – 13 | 28.8% |
+| style recalc time (ms) | 41 | 36 – 41 | 13.3% |
+| long tasks (≥ 50 ms) | 0 | 0 – 1 | 0.0% |
+| long task total (ms) | 0 | 0 – 78 | 0.0% |
+| heap used after GC (MB) | 84.1 | 83.6 – 85.3 | 2.0% |
+
+**Top components (median renders)**
+
+| name | renders |
+| --- | --- |
+| `Button` | 302 |
+| `HugeiconsIcon` | 292 |
+| `Icon` | 292 |
+| `Block` | 256 |
+| `u0` | 120 |
+| `AnimatePresence` | 42 |
+| `FilterChip` | 35 |
+| `PopChild` | 35 |
+| `PopChildMeasure` | 35 |
+| `PresenceChild` | 35 |
+
+**Top render causes (median renders)**
+
+| name | renders |
+| --- | --- |
+| `HugeiconsIcon parent-same-props<-Icon` | 239 |
+| `Icon parent-same-props<-Button` | 218 |
+| `Block parent-same-props<-InfiniteScroll` | 208 |
+| `Button props:onDragStart,onClick,children` | 208 |
+| `u0 context` | 120 |
+| `Button mount` | 54 |
+| `HugeiconsIcon mount` | 53 |
+| `Icon mount` | 53 |
+| `Block mount` | 48 |
+| `AnimatePresence state#5` | 30 |
+
+## builder-load-graph · baseline — median of 3 runs
+
+Added with SECRT-3012: `dev` app code at `8eb406275`, same machine and settings. The window opens on the 1-node workflow and closes 2 s after the last of the 100 nodes is on the canvas. On this code the switch also shows the "Unsaved changes found" popup for the new workflow.
+
+| metric | median | range | spread |
+| --- | --- | --- | --- |
+| commits | 71 | 71 – 74 | 4.2% |
+| total renders | 80,164 | 80,164 – 80,193 | 0.0% |
+| renders per commit | 1,129.1 | 1,083.7 – 1,129.1 | 4.0% |
+| max renders in one commit | 25,160 | 25,160 – 25,160 | 0.0% |
+| script time (ms) | 3,100 | 3,022 – 3,244 | 7.2% |
+| task time (ms) | 3,706 | 3,616 – 3,881 | 7.1% |
+| layout time (ms) | 51 | 48 – 52 | 7.8% |
+| style recalc time (ms) | 111 | 107 – 111 | 3.4% |
+| long tasks (≥ 50 ms) | 4 | 4 – 4 | 0.0% |
+| long task total (ms) | 3,062 | 2,989 – 3,202 | 7.0% |
+| heap used after GC (MB) | 105.0 | 104.8 – 108.1 | 3.1% |
+
+**Top components (median renders)**
+
+| name | renders |
+| --- | --- |
+| `TooltipProvider` | 3,700 |
+| `Text` | 3,370 |
+| `Tooltip` | 3,103 |
+| `TooltipContent` | 3,103 |
+| `Primitive.div` | 3,075 |
+| `HugeiconsIcon` | 3,017 |
+| `Icon` | 3,017 |
+| `Presence` | 2,825 |
+| `Popper` | 2,823 |
+| `PopperProvider` | 2,823 |
+
+**Top render causes (median renders)**
+
+| name | renders |
+| --- | --- |
+| `TooltipProvider props:children` | 2,120 |
+| `Presence props:children` | 2,044 |
+| `HugeiconsIcon parent-same-props<-Icon` | 1,706 |
+| `Primitive.div props:children` | 1,663 |
+| `Primitive.div.Slot props:children` | 1,663 |
+| `Primitive.div.SlotClone props:children` | 1,663 |
+| `Tooltip props:children` | 1,660 |
+| `PopperAnchor props:children` | 1,417 |
+| `Text mount` | 1,260 |
+| `Text props:children` | 1,154 |
diff --git a/docs/engineering/frontend-perf-measurement.md b/docs/engineering/frontend-perf-measurement.md
index 65ed2cb604..38d63326bc 100644
--- a/docs/engineering/frontend-perf-measurement.md
+++ b/docs/engineering/frontend-perf-measurement.md
@@ -127,6 +127,9 @@ Names come from the component function. Third-party code bundled already minifie
| `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 |
| `builder-run-beads` | Open the same 50-node workflow with its RUNNING run; the harness answers the websocket subscribe for that run itself | 10 new node executions over the websocket (a second, finished run of nodes 30 to 39 with new `node_exec_id`s), one every 150 ms, so each edge into one of those StoreValue nodes gets a new bead that travels the edge and is removed on arrival | 2 s after the last event |
| `library-agent-runs` | Open a workflow's page with 20 runs; the newest is RUNNING and selected, so its detail polls every 1.5 s. The websocket is mocked | Three new RUNNING runs arrive at the top of the list, 2.5 s apart: each is pushed as a `graph_execution_event`, the list refetches and the scenario waits for its row; prints the run-list and run-detail `GET`s seen | 1 s after the last run's 2.5 s |
+| `builder-type-field` | Open the same 50-node workflow with no run, click the first node's text field and clear it | Type 20 characters, 50 ms apart | 2 s after the last key |
+| `builder-block-menu-search` | Open the same 50-node workflow with no run and open the block menu | Type "text" into its search, 120 ms a key, wait for the first result, then scroll the results 6 times (800 px, 400 ms apart) so more pages load. Results come from the real backend's block search | 2 s after the last scroll |
+| `builder-load-graph` | Open a 1-node workflow | Switch to a saved 100-node workflow with `history.pushState`, as opening another workflow does, until its last node is on the canvas | 2 s after the last node appears |
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.