1
- import React , { useEffect , useRef , useState } from 'react'
1
+ import React , { useEffect , useMemo , useRef , useState } from 'react'
2
2
import {
3
3
formatMatcher ,
4
4
formatMs ,
@@ -814,6 +814,14 @@ function TraceItem<
814
814
! ! trace . traceContext &&
815
815
! ! trace . finalTransition
816
816
817
+ // Memoize computed results for this trace
818
+ const computedResults = useMemo ( ( ) => {
819
+ if ( trace . traceContext && trace . finalTransition ) {
820
+ return getComputedResults ( trace . traceContext , trace . finalTransition )
821
+ }
822
+ return { computedSpans : { } , computedValues : { } }
823
+ } , [ trace . traceContext , trace . finalTransition ] )
824
+
817
825
// Handle download button click without triggering the expand/collapse
818
826
const handleDownloadClick = ( e : React . MouseEvent ) => {
819
827
e . stopPropagation ( )
@@ -834,12 +842,11 @@ function TraceItem<
834
842
? '#c62828'
835
843
: '#e0e0e0' ,
836
844
} }
837
- onClick = { onToggleExpand }
838
845
onMouseEnter = { ( ) => void setIsHovered ( true ) }
839
846
onMouseLeave = { ( ) => void setIsHovered ( false ) }
840
847
>
841
848
{ /* ROW 1: Title, state, buttons, and IDs */ }
842
- < div style = { styles . historyHeader } >
849
+ < div style = { styles . historyHeader } onClick = { onToggleExpand } >
843
850
< div style = { { display : 'flex' , alignItems : 'center' , gap : '8px' } } >
844
851
< strong style = { { fontSize : '15px' } } > { trace . traceName } </ strong >
845
852
< span
@@ -975,7 +982,12 @@ function TraceItem<
975
982
</ div >
976
983
977
984
{ isExpanded && (
978
- < div style = { styles . expandedHistory } >
985
+ < div
986
+ style = { styles . expandedHistory }
987
+ onClick = { ( e ) => {
988
+ void e . stopPropagation ( )
989
+ } }
990
+ >
979
991
< TraceAttributes attributes = { trace . attributes } />
980
992
981
993
< RequiredSpansList requiredSpans = { trace . requiredSpans } />
@@ -990,30 +1002,32 @@ function TraceItem<
990
1002
< div style = { styles . section } >
991
1003
< div style = { styles . sectionTitle } > Computed Spans:</ div >
992
1004
< ul style = { { listStyle : 'none' , margin : 0 , padding : 0 } } >
993
- { ( trace . computedSpans ?? [ ] ) . map ( ( name ) => (
994
- < li key = { name } style = { styles . listItem } >
995
- { name }
996
- { trace . state === 'complete' || trace . state === 'interrupted'
997
- ? ( ( ) => {
998
- const { computedSpans } =
999
- trace . traceContext && trace . finalTransition
1000
- ? getComputedResults (
1001
- trace . traceContext ,
1002
- trace . finalTransition ,
1003
- )
1004
- : { }
1005
- if ( computedSpans ?. [ name ] ) {
1006
- return (
1007
- < span style = { { marginLeft : 8 , color : '#1976d2' } } >
1008
- { JSON . stringify ( computedSpans [ name ] ) }
1009
- </ span >
1010
- )
1011
- }
1012
- return null
1013
- } ) ( )
1014
- : null }
1015
- </ li >
1016
- ) ) }
1005
+ { ( trace . computedSpans ?? [ ] ) . map ( ( name ) => {
1006
+ const value = computedResults . computedSpans ?. [ name ]
1007
+ return (
1008
+ < li key = { name } style = { styles . listItem } >
1009
+ { name }
1010
+ { trace . state === 'complete' ||
1011
+ trace . state === 'interrupted' ? (
1012
+ value ? (
1013
+ < span style = { { marginLeft : 8 , color : '#1976d2' } } >
1014
+ { JSON . stringify ( value ) }
1015
+ </ span >
1016
+ ) : (
1017
+ < span
1018
+ style = { {
1019
+ marginLeft : 8 ,
1020
+ color : 'red' ,
1021
+ fontWeight : 500 ,
1022
+ } }
1023
+ >
1024
+ missing
1025
+ </ span >
1026
+ )
1027
+ ) : null }
1028
+ </ li >
1029
+ )
1030
+ } ) }
1017
1031
</ ul >
1018
1032
</ div >
1019
1033
< div style = { styles . section } >
@@ -1024,17 +1038,11 @@ function TraceItem<
1024
1038
{ name }
1025
1039
{ trace . state === 'complete' || trace . state === 'interrupted'
1026
1040
? ( ( ) => {
1027
- const { computedValues } =
1028
- trace . traceContext && trace . finalTransition
1029
- ? getComputedResults (
1030
- trace . traceContext ,
1031
- trace . finalTransition ,
1032
- )
1033
- : { }
1034
- if ( computedValues ?. [ name ] !== undefined ) {
1041
+ const value = computedResults . computedValues ?. [ name ]
1042
+ if ( value !== undefined ) {
1035
1043
return (
1036
1044
< span style = { { marginLeft : 8 , color : '#1976d2' } } >
1037
- { String ( computedValues [ name ] ) }
1045
+ { String ( value ) }
1038
1046
</ span >
1039
1047
)
1040
1048
}
@@ -1068,6 +1076,7 @@ function TraceItem<
1068
1076
...styles . expandArrow ,
1069
1077
...( isExpanded ? styles . expandArrowUp : styles . expandArrowDown ) ,
1070
1078
} }
1079
+ onClick = { onToggleExpand }
1071
1080
>
1072
1081
▼
1073
1082
</ div >
0 commit comments