The best way to control Claude Code, Codex and more from any computer or phone
perf(web): the item inspector compiles without manual memoization (#20545)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 22:44 UTC
3ba883ebf4647ab8372f74c47422e53e92e9a53d
1 file changed
+18
-20
apps/web/src/components/chat/V2ItemInspector.tsx
+18
-20
@@ -14,7 +14,7 @@ import {
14
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
15
import { isJavaScriptReplTool } from "@t3tools/shared/toolActivity";
16
import { ExternalLinkIcon, GitBranchIcon, RotateCcwIcon } from "lucide-react";
17
-import { memo, type ReactNode, Suspense, use, useMemo } from "react";
17
+import { memo, type ReactNode, Suspense, use } from "react";
18
19
import { useTheme } from "../../hooks/useTheme";
20
import { cn } from "../../lib/utils";
@@ -54,14 +54,10 @@ function SyntaxTokens({
54
}) {
55
const { resolvedTheme } = useTheme();
56
const highlighter = use(getSyntaxHighlighterPromise(language));
57
- const { tokens } = useMemo(
58
- () =>
59
- highlighter.codeToTokens(text, {
60
- lang: language,
61
- theme: resolveDiffThemeName(resolvedTheme),
62
- }),
63
- [highlighter, text, language, resolvedTheme],
64
- );
57
+ const { tokens } = highlighter.codeToTokens(text, {
58
+ lang: language,
59
+ theme: resolveDiffThemeName(resolvedTheme),
60
+ });
61
return tokens.flatMap((line, lineIndex) => [
62
lineIndex > 0 ? "\n" : "",
63
...line.map((token) => (
@@ -75,6 +71,16 @@ function SyntaxTokens({
71
const monoClassName =
72
"font-mono text-(length:--font-size-code,var(--text-2xs)) leading-relaxed whitespace-pre-wrap break-words select-text";
73
74
+function isJsonText(text: string): boolean {
75
+ if (!text) return false;
76
+ try {
77
+ JSON.parse(text);
78
+ return true;
79
+ } catch {
80
+ return false;
81
+ }
82
+}
83
+
84
function StructuredValue({
85
value,
86
highlightJson = false,
@@ -85,15 +91,7 @@ function StructuredValue({
91
readonly language?: "typescript";
92
}) {
93
const text = typeof value === "string" ? value : JSON.stringify(value, null, 2);
88
- const isJson = useMemo(() => {
89
- if (!highlightJson || !text) return false;
90
- try {
91
- JSON.parse(text);
92
- return true;
93
- } catch {
94
- return false;
95
- }
96
- }, [highlightJson, text]);
94
+ const isJson = highlightJson && isJsonText(text);
95
if (!text) return null;
96
return (
97
<pre className={cn("max-h-80 overflow-auto text-muted-foreground", monoClassName)}>
@@ -309,8 +307,8 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
307
) : null}
308
{item.changes !== undefined && item.changes.length > 0 ? (
309
<ul className="space-y-1 font-mono text-muted-foreground">
312
- {item.changes.map((change, index) => (
313
- <li key={`${change.operation}:${change.path}:${index}`}>
310
+ {item.changes.map((change) => (
311
+ <li key={JSON.stringify([change.operation, change.oldPath, change.path])}>
312
{change.operation} {change.oldPath ? `${change.oldPath} → ` : ""}
313
{formatWorkspaceRelativePath(change.path, props.workspaceRoot)}
314
{change.fileType || change.mimeType