33import { useEffect , useMemo , useRef , useState , type ReactNode } from 'react'
44import useSWR from 'swr'
55import { CompareLayout } from '@/components/compare-layout'
6+ import { DiffTable } from '@/components/diff-table'
67import { ErrorState } from '@/components/error-state'
78import { Sidebar } from '@/components/sidebar'
89import { TopBar , Environment , CompareView } from '@/components/top-bar'
@@ -303,6 +304,18 @@ export default function Home() {
303304 return null
304305 } , [ analyzeData , baselineAnalyzeData , baselineSnapshot , compareFilterSource ] )
305306
307+ // In single-build (non-compare) mode the table view still wants a list
308+ // of every source for the current route. We synthesize this by diffing
309+ // the build against itself, which produces an all-`identical` summary
310+ // that we feed into `<DiffTable mode="single">`. This keeps a single
311+ // sources-listing implementation regardless of mode.
312+ const singleSourceListing = useMemo ( ( ) => {
313+ if ( ! analyzeData || baselineSnapshot ) return null
314+ return diffSources ( analyzeData , analyzeData , {
315+ filterSource : ( _ , index ) => filterSource ( index ) ,
316+ } )
317+ } , [ analyzeData , baselineSnapshot , filterSource ] )
318+
306319 // Per-route totals for both sides, used to size the route-level diff so
307320 // that routes whose modules changed can be reported as `changed` rather
308321 // than `identical`. Only fetched in compare mode.
@@ -402,20 +415,36 @@ export default function Home() {
402415 analyzerContent = (
403416 < >
404417 < div className = "flex-1 min-w-0" >
405- < TreemapVisualizer
406- analyzeData = { analyzeData }
407- sourceIndex = { rootSourceIndex }
408- selectedSourceIndex = { selectedSourceIndex ?? rootSourceIndex }
409- onSelectSourceIndex = { setSelectedSourceIndex }
410- focusedSourceIndex = { focusedSourceIndex ?? rootSourceIndex }
411- onFocusSourceIndex = { setFocusedSourceIndex }
412- isMouseInTreemap = { isMouseInTreemap }
413- onMouseInTreemapChange = { setIsMouseInTreemap }
414- onHoveredNodeChange = { setHoveredNodeInfo }
415- searchQuery = { searchQuery }
416- filterSource = { filterSource }
417- sizeMode = { SizeMode . Compressed }
418- />
418+ { compareView === CompareView . Table && singleSourceListing ? (
419+ < DiffTable
420+ summary = { singleSourceListing }
421+ useCompressed
422+ nameHeading = "Source"
423+ mode = "single"
424+ searchQuery = { searchQuery }
425+ onRowSelect = { ( row ) => {
426+ if ( row . sourceIndexB != null ) {
427+ setSelectedSourceIndex ( row . sourceIndexB )
428+ setFocusedSourceIndex ( row . sourceIndexB )
429+ }
430+ } }
431+ />
432+ ) : (
433+ < TreemapVisualizer
434+ analyzeData = { analyzeData }
435+ sourceIndex = { rootSourceIndex }
436+ selectedSourceIndex = { selectedSourceIndex ?? rootSourceIndex }
437+ onSelectSourceIndex = { setSelectedSourceIndex }
438+ focusedSourceIndex = { focusedSourceIndex ?? rootSourceIndex }
439+ onFocusSourceIndex = { setFocusedSourceIndex }
440+ isMouseInTreemap = { isMouseInTreemap }
441+ onMouseInTreemapChange = { setIsMouseInTreemap }
442+ onHoveredNodeChange = { setHoveredNodeInfo }
443+ searchQuery = { searchQuery }
444+ filterSource = { filterSource }
445+ sizeMode = { SizeMode . Compressed }
446+ />
447+ ) }
419448 </ div >
420449 < button
421450 type = "button"
@@ -440,7 +469,7 @@ export default function Home() {
440469 < main className = "h-screen flex flex-col bg-background" >
441470 < TopBar
442471 hasSourceData = { analyzeData != null }
443- showViewToggle = { isCompareMode }
472+ showViewToggle = { analyzeData != null }
444473 compareView = { compareView }
445474 onCompareViewChange = { setCompareView }
446475 selectedRoute = { selectedRoute }
@@ -465,7 +494,7 @@ export default function Home() {
465494
466495 < div className = "flex-1 flex min-h-0" > { analyzerContent } </ div >
467496
468- { analyzeData && ! isCompareMode ? (
497+ { analyzeData && ! isCompareMode && compareView === CompareView . Treemap ? (
469498 < div className = "flex-none border-t border-border bg-background px-4 py-2 h-10" >
470499 < div className = "text-sm text-muted-foreground" >
471500 { hoveredNodeInfo ? (
0 commit comments