Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,7 @@ jobs:
node scripts/test-new-tests.mjs \
--flake-detection \
--mode dev \
--group ${{ matrix.group }} \
--preview-builds-base-url "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
--group ${{ matrix.group }}
stepName: 'test-new-tests-dev-${{matrix.group}}'
timeout_minutes: 120 # Increase the default timeout as tests are intentionally run multiple times to detect flakes

Expand All @@ -841,8 +840,7 @@ jobs:
node scripts/test-new-tests.mjs \
--flake-detection \
--mode start \
--group ${{ matrix.group }} \
--preview-builds-base-url "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
--group ${{ matrix.group }}
stepName: 'test-new-tests-start-${{matrix.group}}'
timeout_minutes: 120 # Increase the default timeout as tests are intentionally run multiple times to detect flakes
secrets: inherit
Expand Down Expand Up @@ -883,12 +881,11 @@ jobs:

- name: Wait for preview tarball
env:
PREVIEW_BUILDS_BASE_URL: ${{ vars.PREVIEW_BUILDS_BASE_URL }}
NEXT_TEST_PREVIEW_BUILDS_BASE_URL: ${{ vars.PREVIEW_BUILDS_BASE_URL }}
PREVIEW_BUILDS_ACCESS: ${{ vars.PREVIEW_BUILDS_ACCESS }}
run: |
set -euo pipefail
node scripts/wait-for-preview-tarball.mjs \
--preview-builds-base-url "$PREVIEW_BUILDS_BASE_URL" \
--timeout-minutes 30

test-new-tests-deploy:
Expand Down Expand Up @@ -916,8 +913,7 @@ jobs:
export IS_TURBOPACK_TEST=1
node scripts/test-new-tests.mjs \
--mode deploy \
--group ${{ matrix.group }} \
--preview-builds-base-url "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
--group ${{ matrix.group }}
stepName: 'test-new-tests-deploy-${{matrix.group}}'

secrets: inherit
Expand Down Expand Up @@ -948,8 +944,7 @@ jobs:
export IS_TURBOPACK_TEST=1
node scripts/test-new-tests.mjs \
--mode deploy \
--group ${{ matrix.group }} \
--preview-builds-base-url "${{ vars.PREVIEW_BUILDS_BASE_URL }}"
--group ${{ matrix.group }}
stepName: 'test-new-tests-deploy-cache-components-${{matrix.group}}'

secrets: inherit
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ env:
VERCEL_TURBOPACK_TEST_TOKEN: ${{ secrets.VERCEL_TURBOPACK_TEST_TOKEN }}
VERCEL_TURBOPACK_TEST_TEAM: vtest314-next-turbo-e2e-tests
PREVIEW_BUILDS_ACCESS: ${{ vars.PREVIEW_BUILDS_ACCESS }}
NEXT_TEST_PREVIEW_BUILDS_BASE_URL: ${{ vars.PREVIEW_BUILDS_BASE_URL }}
NEXT_TEST_PREFER_OFFLINE: 1
NEXT_CI_RUNNER: ${{ inputs.runs_on_labels }}
NEXT_TEST_PROXY_ADDRESS: ${{ inputs.overrideProxyAddress || '' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_ci_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
jobs:
comment:
name: Comment on PR
if: ${{ github.event.workflow_run.event == 'pull_request' && github.repository == 'vercel/next.js' }}
if: ${{ github.event.workflow_run.event == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/test_e2e_deploy_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ jobs:
NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \
NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \
NEXT_TEST_CLEANUP_SCRIPT_PATH="${{ github.event.inputs.cleanupScriptPath || '' }}" \
NEXT_TEST_PREVIEW_BUILDS_BASE_URL="${{ vars.PREVIEW_BUILDS_BASE_URL }}" \
node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e
testTimingsArtifact: 'test-timings'
skipNativeBuild: 'yes'
Expand Down Expand Up @@ -250,7 +249,6 @@ jobs:
NEXT_TEST_DEPLOY_SCRIPT_PATH="${{ github.event.inputs.deployScriptPath || '' }}" \
NEXT_TEST_DEPLOY_LOGS_SCRIPT_PATH="${{ github.event.inputs.deployLogsScriptPath || '' }}" \
NEXT_TEST_CLEANUP_SCRIPT_PATH="${{ github.event.inputs.cleanupScriptPath || '' }}" \
NEXT_TEST_PREVIEW_BUILDS_BASE_URL="${{ vars.PREVIEW_BUILDS_BASE_URL }}" \
node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e
testTimingsArtifact: 'test-timings'
skipNativeBuild: 'yes'
Expand Down Expand Up @@ -299,7 +297,6 @@ jobs:
VERCEL_CLI_VERSION="${{ github.event.inputs.vercelCliVersion || 'vercel@latest' }}" \
VERCEL_FORCE_BUILD_IN_HIVE="${{ github.event.inputs.forceBuildInHive || '' }}" \
VERCEL_BUILD_CONTAINER_VERSION="${{ github.event.inputs.buildContainerVersion || '' }}" \
NEXT_TEST_PREVIEW_BUILDS_BASE_URL="${{ vars.PREVIEW_BUILDS_BASE_URL }}" \
node run-tests.js --timings --require-timings -g ${{ matrix.group }} -c 2 --type e2e
testTimingsArtifact: 'test-timings'
skipNativeBuild: 'yes'
Expand Down
8 changes: 8 additions & 0 deletions apps/bundle-analyzer/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Bundle analyzer UI

This app enables the Rust React Compiler (`reactCompiler` and `turbopackRustReactCompiler` in `next.config.mjs`). When adding or reviewing UI code:

- Prefer plain derived values and functions over `useMemo`, `useCallback`, or `memo` used only to cache renders or stabilize props; the compiler handles ordinary memoization. Review new instances in every bundle-analyzer change.
- Even expensive pure calculations generally need no manual memo in a component the compiler optimizes. Before keeping one, check compiled output: keep it if the compiler skips that component, if an imperative API needs stable identity, or if measurements show the compiler misses a costly path. Explain the exception in the code.
- Keep **correct dependencies** for effects, subscriptions, and imperative hooks. Do not remove an effect dependency array just to eliminate memoization; dependencies describe behavior, not merely an optimization.
- Verify affected code with the app's typecheck and a production build (`pnpm --filter=@next/bundle-analyzer-ui exec tsc --noEmit` and `pnpm --filter=@next/bundle-analyzer-ui build`) so the compiler actually runs.
175 changes: 125 additions & 50 deletions apps/bundle-analyzer/components/analyzer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
type ErrorInfo,
type ReactNode,
} from 'react'
import Link from 'next/link'
import { usePathname, useSearchParams } from 'next/navigation'
import useSWR from 'swr'
import {
CompareLayout,
Expand Down Expand Up @@ -243,14 +245,17 @@ function useAnalyzerModel(compare: boolean) {
return () => window.removeEventListener('keydown', handleKeyDown)
}, [analyzeData])

// Compute module depth map from active entries
// React Compiler currently skips this hook. Keep the graph traversal cached
// across selection and filter updates until that bailout is resolved.
const moduleDepthMap = useMemo(() => {
if (!analyzeData) return new Map()

const activeEntries = computeActiveEntries(modulesData, analyzeData)
return computeModuleDepthMap(modulesData, activeEntries)
}, [modulesData, analyzeData])

// This hook isn't compiled; stable predicate identity keeps the source diff
// and treemap layout below cached.
const filterSource = useMemo(() => {
if (!analyzeData) return () => true

Expand All @@ -277,7 +282,8 @@ function useAnalyzerModel(compare: boolean) {
// 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.
// sources-listing implementation regardless of mode. Diffing walks every
// source, so keep this cached while this hook isn't compiled.
const singleSourceListing = useMemo(() => {
if (!analyzeData || baselineSnapshot) return null
return diffSources(analyzeData, analyzeData, {
Expand Down Expand Up @@ -442,20 +448,14 @@ function ValidComparisonContent({
baselineRoutes,
baselineBaseDir
)
const routeDiff = useMemo(() => {
if (!model.currentRouteTotals) return null
return diffRoutesWithSizes(
baselineRoutes,
model.currentRoutes,
baselineRouteTotals,
model.currentRouteTotals
)
}, [
baselineRoutes,
model.currentRoutes,
baselineRouteTotals,
model.currentRouteTotals,
])
const routeDiff = model.currentRouteTotals
? diffRoutesWithSizes(
baselineRoutes,
model.currentRoutes,
baselineRouteTotals,
model.currentRouteTotals
)
: null
const layoutProps = {
baselineSnapshot,
comparisonSnapshot: model.comparisonSnapshot,
Expand Down Expand Up @@ -536,41 +536,44 @@ function ComparisonContent({
baselineAnalyzeData: AnalyzeData | null
layoutProps: ComparisonLayoutProps
}) {
const baselineModuleDepthMap = useMemo(() => {
if (!baselineAnalyzeData) return new Map()
const activeEntries = computeActiveEntries(
layoutProps.baselineModulesData,
baselineAnalyzeData
)
return computeModuleDepthMap(layoutProps.baselineModulesData, activeEntries)
}, [layoutProps.baselineModulesData, baselineAnalyzeData])
const compareFilterSource = useMemo(() => {
return (side: 'A' | 'B', sourceIndex: number): boolean => {
const data = side === 'A' ? baselineAnalyzeData : model.analyzeData
if (!data) return false
const flags = data.getSourceFlags(sourceIndex)
const hasEnvironment =
(model.environmentFilter === Environment.Client && flags.client) ||
(model.environmentFilter === Environment.Server && flags.server)
const hasType =
(model.typeFilter.includes('js') && flags.js) ||
(model.typeFilter.includes('css') && flags.css) ||
(model.typeFilter.includes('json') && flags.json) ||
(model.typeFilter.includes('asset') && flags.asset)
return hasEnvironment && hasType
}
}, [
baselineAnalyzeData,
const baselineModuleDepthMap = baselineAnalyzeData
? computeModuleDepthMap(
layoutProps.baselineModulesData,
computeActiveEntries(
layoutProps.baselineModulesData,
baselineAnalyzeData
)
)
: new Map<number, number>()
function compareFilterSource(side: 'A' | 'B', sourceIndex: number): boolean {
const data = side === 'A' ? baselineAnalyzeData : model.analyzeData
if (!data) return false
const flags = data.getSourceFlags(sourceIndex)
const hasEnvironment =
(model.environmentFilter === Environment.Client && flags.client) ||
(model.environmentFilter === Environment.Server && flags.server)
const hasType =
(model.typeFilter.includes('js') && flags.js) ||
(model.typeFilter.includes('css') && flags.css) ||
(model.typeFilter.includes('json') && flags.json) ||
(model.typeFilter.includes('asset') && flags.asset)
return hasEnvironment && hasType
}
const sourceDiff =
model.analyzeData || baselineAnalyzeData
? diffSources(baselineAnalyzeData, model.analyzeData ?? null, {
filterSource: compareFilterSource,
})
: null
const alternateEnvironment = getAlternateEnvironment(model.environmentFilter)
const hasAlternateEnvironmentSources = [
model.analyzeData,
model.environmentFilter,
model.typeFilter,
])
const sourceDiff = useMemo(() => {
if (!model.analyzeData && !baselineAnalyzeData) return null
return diffSources(baselineAnalyzeData, model.analyzeData ?? null, {
filterSource: compareFilterSource,
})
}, [model.analyzeData, baselineAnalyzeData, compareFilterSource])
baselineAnalyzeData,
].some(
(data) =>
data &&
hasEnvironmentSources(data, alternateEnvironment, model.typeFilter)
)
const compareModel: CompareLayoutModel = {
...layoutProps,
selectedRoute: model.selectedRoute,
Expand All @@ -581,6 +584,8 @@ function ComparisonContent({
moduleDepthMap: model.moduleDepthMap,
baselineModuleDepthMap,
environmentFilter: model.environmentFilter,
hasAlternateEnvironmentSources,
setEnvironmentFilter: model.setEnvironmentFilter,
sidebarWidth: model.sidebarWidth,
compareView: model.compareView,
searchQuery: model.searchQuery,
Expand Down Expand Up @@ -620,6 +625,14 @@ function SingleAnalyzerContent({
analyzeData: AnalyzeData
}) {
const rootSourceIndex = getRootSourceIndex(analyzeData)
const hasAlternateEnvironmentSources = hasEnvironmentSources(
analyzeData,
getAlternateEnvironment(model.environmentFilter),
model.typeFilter
)
const alternateEnvironmentEmptyState = hasAlternateEnvironmentSources ? (
<AlternateEnvironmentEmptyState environment={model.environmentFilter} />
) : undefined

return (
<>
Expand All @@ -634,13 +647,19 @@ function SingleAnalyzerContent({
nameHeading="Source"
mode="single"
searchQuery={model.searchQuery}
emptyState={alternateEnvironmentEmptyState}
onRowSelect={(row) => {
if (row.sourceIndexB != null) {
model.setSelectedSourceIndex(row.sourceIndexB)
model.setFocusedSourceIndex(row.sourceIndexB)
}
}}
/>
) : model.singleSourceListing?.rows.length === 0 &&
alternateEnvironmentEmptyState ? (
<div className="flex h-full items-center justify-center p-4 text-sm text-muted-foreground">
{alternateEnvironmentEmptyState}
</div>
) : (
<TreemapVisualizer
analyzeData={analyzeData}
Expand Down Expand Up @@ -677,6 +696,62 @@ function SingleAnalyzerContent({
)
}

function hasEnvironmentSources(
data: AnalyzeData,
environment: Environment,
typeFilter: string[]
): boolean {
for (let index = 0; index < data.sourceCount(); index++) {
const flags = data.getSourceFlags(index)
const hasEnvironment =
(environment === Environment.Client && flags.client) ||
(environment === Environment.Server && flags.server)
const hasType = typeFilter.some(
(type) => flags[type as 'js' | 'css' | 'json' | 'asset']
)
if (hasEnvironment && hasType) {
return true
}
}
return false
}

function getAlternateEnvironment(environment: Environment): Environment {
return environment === Environment.Client
? Environment.Server
: Environment.Client
}

export function AlternateEnvironmentEmptyState({
environment,
}: {
environment: Environment
}) {
const pathname = usePathname()
const searchParams = useSearchParams()
const [currentLabel, alternateLabel] =
environment === Environment.Client
? ['client', 'server']
: ['server', 'client']
const nextSearchParams = new URLSearchParams(searchParams.toString())
nextSearchParams.set('environment', alternateLabel)
const href = `${pathname}?${nextSearchParams.toString()}`

return (
<span>
This route has no {currentLabel} sources matching the active file types.{' '}
<Link
href={href}
replace
className="font-medium text-foreground underline underline-offset-4 hover:text-primary"
>
Show {alternateLabel} sources
</Link>
.
</span>
)
}

function ViewSkeleton({ view }: { view: CompareView }) {
return (
<div className="h-full min-h-0 p-4" role="status" aria-label="Loading view">
Expand Down
Loading
Loading