@@ -30,6 +30,7 @@ export const VirtualizedDiffViewer: React.FC<VirtualizedDiffViewerProps> = ({
3030 miniMapWidth,
3131 inlineDiffOptions,
3232} ) => {
33+ const outerRef = useRef < Node > ( null ) ;
3334 const listRef = useRef < List > ( null ) ;
3435 const [ scrollTop , setScrollTop ] = useState ( 0 ) ;
3536
@@ -167,6 +168,33 @@ export const VirtualizedDiffViewer: React.FC<VirtualizedDiffViewerProps> = ({
167168 onScroll : ( scrollTop : number ) => listRef . current ?. scrollTo ( scrollTop ) ,
168169 } ;
169170
171+ // Observe DOM changes in the diff viewer and update cells with the "empty-equal-cell" class
172+ // whenever new rows are rendered, ensuring virtualized/scroll-loaded cells are handled.
173+ useEffect ( ( ) => {
174+ const container = outerRef . current as HTMLElement | null ;
175+ if ( ! container )
176+ return ;
177+
178+ const observer = new MutationObserver ( ( ) => {
179+ const tds = container ?. querySelectorAll < HTMLTableCellElement > (
180+ ".json-diff-viewer td.line-equal" ,
181+ ) ;
182+
183+ tds . forEach ( ( td , index ) => {
184+ td . classList . remove ( "empty-equal-cell" ) ;
185+
186+ const spans = td . querySelectorAll ( "pre > span" ) ;
187+ if ( index % 2 === 1 && spans . length === 1 && spans [ 0 ] . textContent ?. trim ( ) === "" ) {
188+ td . classList . add ( "empty-equal-cell" ) ;
189+ }
190+ } ) ;
191+ } ) ;
192+
193+ observer . observe ( container ! , { childList : true , subtree : true } ) ;
194+
195+ return ( ) => observer . disconnect ( ) ;
196+ } , [ ] ) ;
197+
170198 return (
171199 < div className = { `diff-viewer-container${ className ? ` ${ className } ` : "" } ` } >
172200 { /* Header & Search */ }
@@ -208,6 +236,7 @@ export const VirtualizedDiffViewer: React.FC<VirtualizedDiffViewerProps> = ({
208236 { /* List & Minimap */ }
209237 < div style = { { display : "flex" , gap : "8px" , position : "relative" } } >
210238 < List
239+ outerRef = { outerRef }
211240 ref = { listRef }
212241 className = "virtual-json-diff-list-container"
213242 height = { height }
0 commit comments