1
- import React , { memo , useEffect , useMemo , useRef , useState } from "react"
1
+ import React , { memo , useCallback , useEffect , useMemo , useRef , useState } from "react"
2
2
import { useSize } from "react-use"
3
3
import { useTranslation , Trans } from "react-i18next"
4
4
import deepEqual from "fast-deep-equal"
@@ -44,7 +44,7 @@ interface ChatRowProps {
44
44
isExpanded : boolean
45
45
isLast : boolean
46
46
isStreaming : boolean
47
- onToggleExpand : ( ) => void
47
+ onToggleExpand : ( ts : number ) => void
48
48
onHeightChange : ( isTaller : boolean ) => void
49
49
onSuggestionClick ?: ( answer : string , event ?: React . MouseEvent ) => void
50
50
}
@@ -103,6 +103,11 @@ export const ChatRowContent = ({
103
103
const [ showCopySuccess , setShowCopySuccess ] = useState ( false )
104
104
const { copyWithFeedback } = useCopyToClipboard ( )
105
105
106
+ // Memoized callback to prevent re-renders caused by inline arrow functions
107
+ const handleToggleExpand = useCallback ( ( ) => {
108
+ onToggleExpand ( message . ts )
109
+ } , [ onToggleExpand , message . ts ] )
110
+
106
111
const [ cost , apiReqCancelReason , apiReqStreamingFailedMessage ] = useMemo ( ( ) => {
107
112
if ( message . text !== null && message . text !== undefined && message . say === "api_req_started" ) {
108
113
const info = safeJsonParse < ClineApiReqInfo > ( message . text )
@@ -302,7 +307,7 @@ export const ChatRowContent = ({
302
307
progressStatus = { message . progressStatus }
303
308
isLoading = { message . partial }
304
309
isExpanded = { isExpanded }
305
- onToggleExpand = { onToggleExpand }
310
+ onToggleExpand = { handleToggleExpand }
306
311
/>
307
312
</ >
308
313
)
@@ -328,7 +333,7 @@ export const ChatRowContent = ({
328
333
progressStatus = { message . progressStatus }
329
334
isLoading = { message . partial }
330
335
isExpanded = { isExpanded }
331
- onToggleExpand = { onToggleExpand }
336
+ onToggleExpand = { handleToggleExpand }
332
337
/>
333
338
</ >
334
339
)
@@ -350,7 +355,7 @@ export const ChatRowContent = ({
350
355
progressStatus = { message . progressStatus }
351
356
isLoading = { message . partial }
352
357
isExpanded = { isExpanded }
353
- onToggleExpand = { onToggleExpand }
358
+ onToggleExpand = { handleToggleExpand }
354
359
/>
355
360
</ >
356
361
)
@@ -389,7 +394,7 @@ export const ChatRowContent = ({
389
394
language = { getLanguageFromPath ( tool . path || "" ) || "log" }
390
395
isLoading = { message . partial }
391
396
isExpanded = { isExpanded }
392
- onToggleExpand = { onToggleExpand }
397
+ onToggleExpand = { handleToggleExpand }
393
398
/>
394
399
</ >
395
400
)
@@ -435,7 +440,7 @@ export const ChatRowContent = ({
435
440
language = "markdown"
436
441
isLoading = { message . partial }
437
442
isExpanded = { isExpanded }
438
- onToggleExpand = { onToggleExpand }
443
+ onToggleExpand = { handleToggleExpand }
439
444
/>
440
445
</ >
441
446
)
@@ -455,7 +460,7 @@ export const ChatRowContent = ({
455
460
code = { tool . content }
456
461
language = "shell-session"
457
462
isExpanded = { isExpanded }
458
- onToggleExpand = { onToggleExpand }
463
+ onToggleExpand = { handleToggleExpand }
459
464
/>
460
465
</ >
461
466
)
@@ -475,7 +480,7 @@ export const ChatRowContent = ({
475
480
code = { tool . content }
476
481
language = "shellsession"
477
482
isExpanded = { isExpanded }
478
- onToggleExpand = { onToggleExpand }
483
+ onToggleExpand = { handleToggleExpand }
479
484
/>
480
485
</ >
481
486
)
@@ -495,7 +500,7 @@ export const ChatRowContent = ({
495
500
code = { tool . content }
496
501
language = "markdown"
497
502
isExpanded = { isExpanded }
498
- onToggleExpand = { onToggleExpand }
503
+ onToggleExpand = { handleToggleExpand }
499
504
/>
500
505
</ >
501
506
)
@@ -525,7 +530,7 @@ export const ChatRowContent = ({
525
530
code = { tool . content }
526
531
language = "shellsession"
527
532
isExpanded = { isExpanded }
528
- onToggleExpand = { onToggleExpand }
533
+ onToggleExpand = { handleToggleExpand }
529
534
/>
530
535
</ >
531
536
)
@@ -813,7 +818,7 @@ export const ChatRowContent = ({
813
818
MozUserSelect : "none" ,
814
819
msUserSelect : "none" ,
815
820
} }
816
- onClick = { onToggleExpand } >
821
+ onClick = { handleToggleExpand } >
817
822
< div style = { { display : "flex" , alignItems : "center" , gap : "10px" , flexGrow : 1 } } >
818
823
{ icon }
819
824
{ title }
@@ -852,7 +857,7 @@ export const ChatRowContent = ({
852
857
code = { safeJsonParse < any > ( message . text ) ?. request }
853
858
language = "markdown"
854
859
isExpanded = { true }
855
- onToggleExpand = { onToggleExpand }
860
+ onToggleExpand = { handleToggleExpand }
856
861
/>
857
862
</ div >
858
863
) }
@@ -898,7 +903,7 @@ export const ChatRowContent = ({
898
903
language = "diff"
899
904
isFeedback = { true }
900
905
isExpanded = { isExpanded }
901
- onToggleExpand = { onToggleExpand }
906
+ onToggleExpand = { handleToggleExpand }
902
907
/>
903
908
</ div >
904
909
)
@@ -945,7 +950,7 @@ export const ChatRowContent = ({
945
950
code = { message . text }
946
951
language = "json"
947
952
isExpanded = { true }
948
- onToggleExpand = { onToggleExpand }
953
+ onToggleExpand = { handleToggleExpand }
949
954
/>
950
955
</ div >
951
956
</ >
@@ -1105,7 +1110,7 @@ export const ChatRowContent = ({
1105
1110
code = { useMcpServer . arguments }
1106
1111
language = "json"
1107
1112
isExpanded = { true }
1108
- onToggleExpand = { onToggleExpand }
1113
+ onToggleExpand = { handleToggleExpand }
1109
1114
/>
1110
1115
</ div >
1111
1116
) }
0 commit comments