@devries-cameron20 / t3code Mirror · read-only / commits / 38b43572be
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 06:45 UTC

perf(web): the MCP app frame compiles without manual memoization (#20691)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 21:49 UTC 38b43572be93a8c35c955303cdc237da134ba7a8
1 file changed +22 -18
apps/web/src/components/chat/McpAppFrame.tsx
+22 -18
@@ -19,7 +19,7 @@ import {
19 type McpAppReference,
20 } from "@t3tools/shared/mcpApp";
21 import { Minimize2Icon } from "lucide-react";
22 -import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
22 +import { useEffect, useLayoutEffect, useRef, useState } from "react";
23 import { flushSync } from "react-dom";
24
25 import { useAssetUrlRefresh, useAssetUrlState } from "~/assets/assetUrls";
@@ -60,6 +60,18 @@ function saveBlob(blob: Blob, name: string) {
60 setTimeout(() => URL.revokeObjectURL(url), 60_000);
61 }
62
63 +// The host gets the tool call pushed by an effect keyed on it, so it stays
64 +// stable across the command hooks that follow.
65 +function useToolCall(
66 + storedItem: NonNullable<ReturnType<typeof useTurnItemDetail>["data"]>["item"] | undefined,
67 +) {
68 + "use memo";
69 + if (storedItem?.type !== "dynamic_tool") return undefined;
70 + const output = storedItem.output as { readonly result?: unknown } | undefined;
71 + const result = output?.result as McpAppCallToolResult | undefined;
72 + return { arguments: storedItem.input, result };
73 +}
74 +
75 export function McpAppFrame(props: {
76 readonly environmentId: EnvironmentId;
77 readonly threadId: ThreadId;
@@ -91,17 +103,14 @@ export function McpAppFrame(props: {
103 // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Closing and reopening replaces the box.
104 }, [closed]);
105
94 - const resource = useMemo(
95 - () => ({
96 - _tag: "attachment" as const,
97 - attachmentId: app.attachmentId,
98 - fileName: mcpAppFileName(app),
99 - mimeType: "text/html",
100 - disposition: "inline" as const,
101 - renderIntent: "mcp-app" as const,
102 - }),
103 - [app],
104 - );
106 + const resource = {
107 + _tag: "attachment" as const,
108 + attachmentId: app.attachmentId,
109 + fileName: mcpAppFileName(app),
110 + mimeType: "text/html",
111 + disposition: "inline" as const,
112 + renderIntent: "mcp-app" as const,
113 + };
114 const asset = useAssetUrlState(props.environmentId, resource);
115 const refreshAsset = useAssetUrlRefresh(props.environmentId, resource);
116 // The frame keeps its first URL: a re-minted one would reload the app. A
@@ -133,12 +142,7 @@ export function McpAppFrame(props: {
142 revision: props.revision,
143 });
144 const storedItem = detail.data?.item;
136 - const toolCall = useMemo(() => {
137 - if (storedItem?.type !== "dynamic_tool") return undefined;
138 - const output = storedItem.output as { readonly result?: unknown } | undefined;
139 - const result = output?.result as McpAppCallToolResult | undefined;
140 - return { arguments: storedItem.input, result };
141 - }, [storedItem]);
145 + const toolCall = useToolCall(storedItem);
146
147 const callTool = useAtomCommand(mcpAppEnvironment.callTool, { reportFailure: false });
148 const toolInfo = useAtomCommand(mcpAppEnvironment.toolInfo, { reportFailure: false });