Skip to content

Commit 4732786

Browse files
perf(web): the item inspector compiles without manual memoization
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7111501 commit 4732786

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

‎apps/web/reactCompiledFiles.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ export const REACT_COMPILED_FILES = [
9696
"apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx",
9797
"apps/web/src/components/ThreadTerminalDrawer.tsx",
9898
"apps/web/src/components/settings/SettingsPanels.tsx",
99+
"apps/web/src/components/chat/V2ItemInspector.tsx",
99100
] as const;

‎apps/web/src/components/chat/V2ItemInspector.tsx‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
1515
import { isJavaScriptReplTool } from "@t3tools/shared/toolActivity";
1616
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";
1818

1919
import { useTheme } from "../../hooks/useTheme";
2020
import { cn } from "../../lib/utils";
@@ -54,14 +54,10 @@ function SyntaxTokens({
5454
}) {
5555
const { resolvedTheme } = useTheme();
5656
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+
});
6561
return tokens.flatMap((line, lineIndex) => [
6662
lineIndex > 0 ? "\n" : "",
6763
...line.map((token) => (
@@ -75,6 +71,16 @@ function SyntaxTokens({
7571
const monoClassName =
7672
"font-mono text-(length:--font-size-code,var(--text-2xs)) leading-relaxed whitespace-pre-wrap break-words select-text";
7773

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+
7884
function StructuredValue({
7985
value,
8086
highlightJson = false,
@@ -85,15 +91,7 @@ function StructuredValue({
8591
readonly language?: "typescript";
8692
}) {
8793
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);
9795
if (!text) return null;
9896
return (
9997
<pre className={cn("max-h-80 overflow-auto text-muted-foreground", monoClassName)}>
@@ -309,8 +307,8 @@ export const V2ItemInspector = memo(function V2ItemInspector(props: V2ItemInspec
309307
) : null}
310308
{item.changes !== undefined && item.changes.length > 0 ? (
311309
<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={`${change.operation}:${change.oldPath ?? ""}:${change.path}`}>
314312
{change.operation} {change.oldPath ? `${change.oldPath} → ` : ""}
315313
{formatWorkspaceRelativePath(change.path, props.workspaceRoot)}
316314
{change.fileType || change.mimeType

0 commit comments

Comments
 (0)