From 6fbba169cd7f46cafeaf334a6a0fb3eebba20d2c Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Thu, 10 Sep 2026 12:47:56 -0700 Subject: [PATCH] bundle-analyzer: add table view to single-build analyzer (#93523) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Will Binns-Smith <755844+wbinnssmith@users.noreply.github.com> --- apps/bundle-analyzer/app/page.tsx | 61 +++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/apps/bundle-analyzer/app/page.tsx b/apps/bundle-analyzer/app/page.tsx index fe14b27cdf7..d848ba668d4 100644 --- a/apps/bundle-analyzer/app/page.tsx +++ b/apps/bundle-analyzer/app/page.tsx @@ -3,6 +3,7 @@ import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react' import useSWR from 'swr' import { CompareLayout } from '@/components/compare-layout' +import { DiffTable } from '@/components/diff-table' import { ErrorState } from '@/components/error-state' import { Sidebar } from '@/components/sidebar' import { TopBar, Environment, CompareView } from '@/components/top-bar' @@ -303,6 +304,18 @@ export default function Home() { return null }, [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 ``. 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 // that routes whose modules changed can be reported as `changed` rather // than `identical`. Only fetched in compare mode. @@ -402,20 +415,36 @@ export default function Home() { analyzerContent = ( <>
- + {compareView === CompareView.Table && singleSourceListing ? ( + { + if (row.sourceIndexB != null) { + setSelectedSourceIndex(row.sourceIndexB) + setFocusedSourceIndex(row.sourceIndexB) + } + }} + /> + ) : ( + + )}