Unverified Commit 6fbba169 authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

bundle-analyzer: add table view to single-build analyzer (#93523)

Extends the view toggle (introduced in the previous PR for compare mode)
to single-build mode as well. The table view lists all sources for the
selected route with sizes and env badges. Internally it reuses
`DiffTable` in `mode="single"` by diffing the build against itself,
which produces an all-`identical` summary — this keeps a single
source-listing implementation regardless of mode.

<!-- NEXT_JS_LLM_PR -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent 0bdea678
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react' import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
import useSWR from 'swr' import useSWR from 'swr'
import { CompareLayout } from '@/components/compare-layout' import { CompareLayout } from '@/components/compare-layout'
import { DiffTable } from '@/components/diff-table'
import { ErrorState } from '@/components/error-state' import { ErrorState } from '@/components/error-state'
import { Sidebar } from '@/components/sidebar' import { Sidebar } from '@/components/sidebar'
import { TopBar, Environment, CompareView } from '@/components/top-bar' import { TopBar, Environment, CompareView } from '@/components/top-bar'
...@@ -303,6 +304,18 @@ export default function Home() { ...@@ -303,6 +304,18 @@ export default function Home() {
return null return null
}, [analyzeData, baselineAnalyzeData, baselineSnapshot, compareFilterSource]) }, [analyzeData, baselineAnalyzeData, baselineSnapshot, compareFilterSource])
// In single-build (non-compare) mode the table view still wants a list
// of every source for the current route. We synthesize this by diffing
// the build against itself, which produces an all-`identical` summary
// that we feed into `<DiffTable mode="single">`. This keeps a single
// sources-listing implementation regardless of mode.
const singleSourceListing = useMemo(() => {
if (!analyzeData || baselineSnapshot) return null
return diffSources(analyzeData, analyzeData, {
filterSource: (_, index) => filterSource(index),
})
}, [analyzeData, baselineSnapshot, filterSource])
// Per-route totals for both sides, used to size the route-level diff so // Per-route totals for both sides, used to size the route-level diff so
// that routes whose modules changed can be reported as `changed` rather // that routes whose modules changed can be reported as `changed` rather
// than `identical`. Only fetched in compare mode. // than `identical`. Only fetched in compare mode.
...@@ -402,20 +415,36 @@ export default function Home() { ...@@ -402,20 +415,36 @@ export default function Home() {
analyzerContent = ( analyzerContent = (
<> <>
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<TreemapVisualizer {compareView === CompareView.Table && singleSourceListing ? (
analyzeData={analyzeData} <DiffTable
sourceIndex={rootSourceIndex} summary={singleSourceListing}
selectedSourceIndex={selectedSourceIndex ?? rootSourceIndex} useCompressed
onSelectSourceIndex={setSelectedSourceIndex} nameHeading="Source"
focusedSourceIndex={focusedSourceIndex ?? rootSourceIndex} mode="single"
onFocusSourceIndex={setFocusedSourceIndex} searchQuery={searchQuery}
isMouseInTreemap={isMouseInTreemap} onRowSelect={(row) => {
onMouseInTreemapChange={setIsMouseInTreemap} if (row.sourceIndexB != null) {
onHoveredNodeChange={setHoveredNodeInfo} setSelectedSourceIndex(row.sourceIndexB)
searchQuery={searchQuery} setFocusedSourceIndex(row.sourceIndexB)
filterSource={filterSource} }
sizeMode={SizeMode.Compressed} }}
/> />
) : (
<TreemapVisualizer
analyzeData={analyzeData}
sourceIndex={rootSourceIndex}
selectedSourceIndex={selectedSourceIndex ?? rootSourceIndex}
onSelectSourceIndex={setSelectedSourceIndex}
focusedSourceIndex={focusedSourceIndex ?? rootSourceIndex}
onFocusSourceIndex={setFocusedSourceIndex}
isMouseInTreemap={isMouseInTreemap}
onMouseInTreemapChange={setIsMouseInTreemap}
onHoveredNodeChange={setHoveredNodeInfo}
searchQuery={searchQuery}
filterSource={filterSource}
sizeMode={SizeMode.Compressed}
/>
)}
</div> </div>
<button <button
type="button" type="button"
...@@ -440,7 +469,7 @@ export default function Home() { ...@@ -440,7 +469,7 @@ export default function Home() {
<main className="h-screen flex flex-col bg-background"> <main className="h-screen flex flex-col bg-background">
<TopBar <TopBar
hasSourceData={analyzeData != null} hasSourceData={analyzeData != null}
showViewToggle={isCompareMode} showViewToggle={analyzeData != null}
compareView={compareView} compareView={compareView}
onCompareViewChange={setCompareView} onCompareViewChange={setCompareView}
selectedRoute={selectedRoute} selectedRoute={selectedRoute}
...@@ -465,7 +494,7 @@ export default function Home() { ...@@ -465,7 +494,7 @@ export default function Home() {
<div className="flex-1 flex min-h-0">{analyzerContent}</div> <div className="flex-1 flex min-h-0">{analyzerContent}</div>
{analyzeData && !isCompareMode ? ( {analyzeData && !isCompareMode && compareView === CompareView.Treemap ? (
<div className="flex-none border-t border-border bg-background px-4 py-2 h-10"> <div className="flex-none border-t border-border bg-background px-4 py-2 h-10">
<div className="text-sm text-muted-foreground"> <div className="text-sm text-muted-foreground">
{hoveredNodeInfo ? ( {hoveredNodeInfo ? (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment