@@ -68,34 +68,41 @@ ListChildComponentProps<{
6868
6969 const [ lDiff , rDiff ]
7070 = leftPart . type === "modify" && rightPart . type === "modify"
71- ? getInlineDiff ( leftPart . text , rightPart . text , inlineDiffOptions ?? { mode : "char" } )
71+ ? getInlineDiff ( leftPart . text || "" , rightPart . text || "" , inlineDiffOptions ?? { mode : "char" } )
7272 : [ [ ] , [ ] ] ;
7373
74- const lTokens = syntaxHighlightLine ( true , leftPart . text , 0 ) ;
75- const rTokens = syntaxHighlightLine ( true , rightPart . text , 0 ) ;
74+ const lTokens = syntaxHighlightLine ( true , leftPart . text || "" , 0 ) ;
75+ const rTokens = syntaxHighlightLine ( true , rightPart . text || "" , 0 ) ;
7676
7777 const lResult = mergeSegments ( lTokens , lDiff ) ;
7878 const rResult = mergeSegments ( rTokens , rDiff ) ;
7979
80- const renderInlineResult = ( text : string , result : typeof lResult , comma ?: boolean ) => (
81- < >
82- { result . map ( ( item , idx ) => {
83- const frag = text . slice ( item . start , item . end ) ;
84- const className = [
85- item . type ? `inline-diff-${ item . type } ` : "" ,
86- item . token ? `token ${ item . token } ` : "" ,
87- ]
88- . filter ( Boolean )
89- . join ( " " ) ;
90- return (
91- < span key = { `${ idx } -${ item . type } -${ frag } ` } className = { className } >
92- { frag }
93- </ span >
94- ) ;
95- } ) }
96- { comma && < span className = "token punctuation" > ,</ span > }
97- </ >
98- ) ;
80+ const renderInlineResult = ( text : string , result : typeof lResult , comma ?: boolean ) => {
81+ // Guard against undefined or null text
82+ if ( ! text || typeof text !== "string" ) {
83+ return < span className = "token plain" > </ span > ;
84+ }
85+
86+ return (
87+ < >
88+ { result . map ( ( item , idx ) => {
89+ const frag = text . slice ( item . start , item . end ) ;
90+ const className = [
91+ item . type ? `inline-diff-${ item . type } ` : "" ,
92+ item . token ? `token ${ item . token } ` : "" ,
93+ ]
94+ . filter ( Boolean )
95+ . join ( " " ) ;
96+ return (
97+ < span key = { `${ idx } -${ item . type } -${ frag } ` } className = { className } >
98+ { frag }
99+ </ span >
100+ ) ;
101+ } ) }
102+ { comma && < span className = "token punctuation" > ,</ span > }
103+ </ >
104+ ) ;
105+ } ;
99106
100107 return (
101108 < div
@@ -115,7 +122,7 @@ ListChildComponentProps<{
115122 < div className = { `cell line-${ leftPart . type } ${ equalEmptyLine ( leftPart ) } ` } role = "cell" >
116123 < pre >
117124 { leftPart . text && indentChar . repeat ( leftPart . level * indentSize ) }
118- { renderInlineResult ( leftPart . text , lResult , leftPart . comma ) }
125+ { renderInlineResult ( leftPart . text || "" , lResult , leftPart . comma ) }
119126 </ pre >
120127 </ div >
121128
@@ -126,7 +133,7 @@ ListChildComponentProps<{
126133 < div className = { `cell line-${ rightPart . type } ${ equalEmptyLine ( rightPart ) } ` } role = "cell" >
127134 < pre >
128135 { rightPart . text && indentChar . repeat ( rightPart . level * indentSize ) }
129- { renderInlineResult ( rightPart . text , rResult , rightPart . comma ) }
136+ { renderInlineResult ( rightPart . text || "" , rResult , rightPart . comma ) }
130137 </ pre >
131138 </ div >
132139 </ div >
0 commit comments