@@ -8,14 +8,46 @@ const ToolTipDataDisplay = ({ data }) => {
8
8
scheme : 'custom' ,
9
9
base00 : 'transparent' ,
10
10
base0B : '#1f2937' , // dark navy for strings
11
- base0D : '#60a5fa' , // Blue for keys
12
- base09 : '#f59e0b' , // Orange for numbers
13
- base0C : '#EF4444' , // red for nulls
11
+ base0D : '#60a5fa' , // Keys
12
+ base09 : '#f59e0b' , // Numbers
13
+ base0C : '#EF4444' , // Null values
14
+ } ;
15
+
16
+ // Helper function to parse stringified JSON in object values
17
+ const parseStringifiedValues = ( obj ) => {
18
+ if ( ! obj || typeof obj !== 'object' ) return obj ;
19
+
20
+ const parsed = { ...obj } ;
21
+ for ( const key in parsed ) {
22
+ if ( typeof parsed [ key ] === 'string' ) {
23
+ try {
24
+ // Check if the string looks like JSON
25
+ if ( parsed [ key ] . startsWith ( '{' ) || parsed [ key ] . startsWith ( '[' ) ) {
26
+ const parsedValue = JSON . parse ( parsed [ key ] ) ;
27
+ parsed [ key ] = parsedValue ;
28
+ }
29
+ } catch ( e ) {
30
+ // If parsing fails, keep original value
31
+ continue ;
32
+ }
33
+ } else if ( typeof parsed [ key ] === 'object' ) {
34
+ parsed [ key ] = parseStringifiedValues ( parsed [ key ] ) ;
35
+ }
36
+ }
37
+ return parsed ;
14
38
} ;
15
39
16
40
const formatReducerData = ( reducerStates ) => {
41
+ // Check if reducerStates exists and is an array
42
+ if ( ! Array . isArray ( reducerStates ) ) {
43
+ return { } ;
44
+ }
45
+
17
46
return reducerStates . reduce ( ( acc , reducer ) => {
18
- acc [ reducer . hookName || 'Reducer' ] = reducer . state ;
47
+ // Add additional type checking for reducer object
48
+ if ( reducer && typeof reducer === 'object' ) {
49
+ acc [ reducer . hookName || 'Reducer' ] = reducer . state ;
50
+ }
19
51
return acc ;
20
52
} , { } ) ;
21
53
} ;
@@ -29,8 +61,18 @@ const ToolTipDataDisplay = ({ data }) => {
29
61
return null ;
30
62
}
31
63
32
- if ( isReducer ) {
33
- const formattedData = formatReducerData ( content ) ;
64
+ // Parse any stringified JSON before displaying
65
+ const parsedContent = parseStringifiedValues ( content ) ;
66
+
67
+ if ( isReducer && parsedContent ) {
68
+ // Only try to format if we have valid content
69
+ const formattedData = formatReducerData ( parsedContent ) ;
70
+
71
+ // Check if we have any formatted data to display
72
+ if ( Object . keys ( formattedData ) . length === 0 ) {
73
+ return null ;
74
+ }
75
+
34
76
return (
35
77
< div className = 'tooltip-section' >
36
78
{ Object . entries ( formattedData ) . map ( ( [ hookName , state ] ) => (
@@ -49,17 +91,17 @@ const ToolTipDataDisplay = ({ data }) => {
49
91
< div className = 'tooltip-section' >
50
92
< div className = 'tooltip-section-title' > { title } </ div >
51
93
< div className = 'tooltip-data' >
52
- < JSONTree data = { content } theme = { jsonTheme } hideRoot shouldExpandNode = { ( ) => true } />
94
+ < JSONTree data = { parsedContent } theme = { jsonTheme } hideRoot shouldExpandNode = { ( ) => true } />
53
95
</ div >
54
96
</ div >
55
97
) ;
56
98
} ;
57
99
58
100
return (
59
101
< div className = 'tooltip-container' >
60
- { renderSection ( 'Props' , data . componentData . props ) }
61
- { renderSection ( 'State' , data . componentData . state || data . componentData . hooksState ) }
62
- { renderSection ( null , data . componentData . reducerStates , true ) }
102
+ { renderSection ( 'Props' , data . componentData ? .props ) }
103
+ { renderSection ( 'State' , data . componentData ? .state || data . componentData ? .hooksState ) }
104
+ { renderSection ( null , data . componentData ? .reducerStates , true ) }
63
105
</ div >
64
106
) ;
65
107
} ;
0 commit comments