The best way to control Claude Code, Codex and more from any computer or phone
perf(web): the command output panel compiles without manual memoization (#20658)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 21:56 UTC
35548e27e875577f10d263d4a532fcd214540fdd
1 file changed
+9
-5
apps/web/src/components/chat/CommandOutputPanel.tsx
+9
-5
@@ -1,6 +1,6 @@
1
import type { EnvironmentId, ThreadId, TurnItemId } from "@t3tools/contracts";
2
import { TERMINAL_PALETTES, terminalOutputSpans } from "@t3tools/shared/terminalOutput";
3
-import { useLayoutEffect, useMemo, useRef } from "react";
3
+import { useLayoutEffect, useRef } from "react";
4
5
import { useTheme } from "../../hooks/useTheme";
6
import { useServerConfigs } from "../../state/entities";
@@ -22,6 +22,13 @@ export function useCommandOutputStreaming(environmentId: EnvironmentId): boolean
22
* shows its final output. Mount it only when `useCommandOutputStreaming` holds.
23
* It subscribes only while mounted, so collapsed rows and other threads receive nothing.
24
*/
25
+// Parsing ANSI output is linear in its length, and the compiler would redo it on
26
+// every render because the layout effect runs after it.
27
+function useTerminalOutputSpans(text: string, resolvedTheme: keyof typeof TERMINAL_PALETTES) {
28
+ "use memo";
29
+ return terminalOutputSpans(text, TERMINAL_PALETTES[resolvedTheme]);
30
+}
31
+
32
export function CommandOutputPanel(props: {
33
readonly environmentId: EnvironmentId;
34
readonly threadId: ThreadId;
@@ -38,10 +45,7 @@ export function CommandOutputPanel(props: {
45
const followRef = useRef(true);
46
const text = data?.output.text ?? "";
47
const { resolvedTheme } = useTheme();
41
- const spans = useMemo(
42
- () => terminalOutputSpans(text, TERMINAL_PALETTES[resolvedTheme]),
43
- [text, resolvedTheme],
44
- );
48
+ const spans = useTerminalOutputSpans(text, resolvedTheme);
49
50
// This panel only re-renders when its output changes, so keep the end in view after each.
51
useLayoutEffect(() => {