@@ -14,7 +14,7 @@ import {
1414import { formatDiffCount } from "@t3tools/client-runtime/diff-count" ;
1515import { isJavaScriptReplTool } from "@t3tools/shared/toolActivity" ;
1616import { 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
1919import { useTheme } from "../../hooks/useTheme" ;
2020import { 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({
7571const 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+
7884function 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