Unverified Commit 18e7c84a authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Remove JS size reporting from next build (#83815)

## What

Remove the `First Used JS` and `Size` metrics from `next build` CLI output, as well as the manifest files that supported these metrics.

## Why

A recent investigation has revealed a number of bugs and longstanding known issues in the implementation.

* The metrics produced by Webpack builds for App Router don't account for layouts and parallel routes correctly.
   * Not only are they not accounted for in route sizes, they are treated as distinct routes for the 'uniqueness' computation which means dependencies of a widely shared layout wouldn't be treated as 'common chunks'
* The `First Used JS by All` metric counts `.css` chunks as JS
    * This happened to predominately affect turbopack reporting due the above issue in webpack (css deps of layouts don't get treated as common deps)
* In App router, client components are not accurately modeled by either toolchain
   * webpack doesn't account for client components at all.  Leading to consistent undercounts
   * turbopack accumulates all referenced client components which is better but can be an overcount for conditionally rendered or mutually exclusive components.
*  In Pages router, `next/dynamic` dependencies can confuse these metrics

Generally, if a server is using any non-trivial logic to decide what is rendered there is just no correct answer to the 'First Load JS size' question.   These metrics originally came out of a collaboration with Chrome DevRel back in 2019 (maybe? first reference i think is https://github.com/vercel/next.js/pull/7194).  Since then, the web has shifted to Core Web Vitals and indeed that is what we use to evaluate actual performance.

We've decided to remove the metric instead as it's misleading at this point.

See #83823 for docs updates
parent 0f27700f
...@@ -23,8 +23,8 @@ use next_core::{ ...@@ -23,8 +23,8 @@ use next_core::{
next_dynamic::NextDynamicTransition, next_dynamic::NextDynamicTransition,
next_edge::route_regex::get_named_middleware_regex, next_edge::route_regex::get_named_middleware_regex,
next_manifests::{ next_manifests::{
AppBuildManifest, AppPathsManifest, BuildManifest, ClientReferenceManifest, AppPathsManifest, BuildManifest, ClientReferenceManifest, EdgeFunctionDefinition,
EdgeFunctionDefinition, MiddlewareMatcher, MiddlewaresManifestV2, PagesManifest, Regions, MiddlewareMatcher, MiddlewaresManifestV2, PagesManifest, Regions,
client_reference_manifest::ClientReferenceManifestOptions, client_reference_manifest::ClientReferenceManifestOptions,
}, },
next_server::{ next_server::{
...@@ -40,7 +40,7 @@ use tracing::Instrument; ...@@ -40,7 +40,7 @@ use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
Completion, FxIndexSet, NonLocalValue, ResolvedVc, TryJoinIterExt, ValueToString, Vc, Completion, FxIndexSet, NonLocalValue, ResolvedVc, TryJoinIterExt, ValueToString, Vc,
fxindexmap, fxindexset, trace::TraceRawVcs, fxindexset, trace::TraceRawVcs,
}; };
use turbo_tasks_env::{CustomProcessEnv, ProcessEnv}; use turbo_tasks_env::{CustomProcessEnv, ProcessEnv};
use turbo_tasks_fs::{File, FileContent, FileSystemPath}; use turbo_tasks_fs::{File, FileContent, FileSystemPath};
...@@ -1154,7 +1154,7 @@ impl AppEndpoint { ...@@ -1154,7 +1154,7 @@ impl AppEndpoint {
enum EmitManifests { enum EmitManifests {
/// Don't emit any manifests (needed for the RSC endpoints) /// Don't emit any manifests (needed for the RSC endpoints)
None, None,
/// Emit the manifest for basic Next.js functionality (e.g. app-build-manifest.json) /// Emit the manifest for basic Next.js functionality
Minimal, Minimal,
/// All manifests: `Minimal` plus next-font, next-dynamic, ... /// All manifests: `Minimal` plus next-font, next-dynamic, ...
Full, Full,
...@@ -1312,30 +1312,6 @@ impl AppEndpoint { ...@@ -1312,30 +1312,6 @@ impl AppEndpoint {
let manifest_path_prefix = &app_entry.original_name; let manifest_path_prefix = &app_entry.original_name;
if emit_manifests != EmitManifests::None {
let app_build_manifest = AppBuildManifest {
pages: fxindexmap!(
app_entry.original_name.clone() => ResolvedVc::cell(entry_client_chunks
.iter()
.chain(client_shared_chunks.iter())
.copied()
.collect())
),
};
let app_build_manifest_output = app_build_manifest
.build_output(
node_root.join(&format!(
"server/app{manifest_path_prefix}/app-build-manifest.json",
))?,
client_relative_path.clone(),
)
.await?
.to_resolved()
.await?;
server_assets.insert(app_build_manifest_output);
}
// polyfill-nomodule.js is a pre-compiled asset distributed as part of next, // polyfill-nomodule.js is a pre-compiled asset distributed as part of next,
// load it as a RawModule. // load it as a RawModule.
let next_package = get_next_package(project.project_path().owned().await?) let next_package = get_next_package(project.project_path().owned().await?)
......
...@@ -84,7 +84,6 @@ ...@@ -84,7 +84,6 @@
"scrollRestoration": false, "scrollRestoration": false,
"externalDir": false, "externalDir": false,
"disableOptimizedLoading": false, "disableOptimizedLoading": false,
"gzipSize": true,
"craCompat": false, "craCompat": false,
"esmExternals": true, "esmExternals": true,
"fullySpecified": false, "fullySpecified": false,
......
...@@ -439,79 +439,6 @@ pub struct FontManifestEntry { ...@@ -439,79 +439,6 @@ pub struct FontManifestEntry {
pub content: RcStr, pub content: RcStr,
} }
#[derive(Default, Debug)]
pub struct AppBuildManifest {
pub pages: FxIndexMap<RcStr, ResolvedVc<OutputAssets>>,
}
impl AppBuildManifest {
pub async fn build_output(
self,
output_path: FileSystemPath,
client_relative_path: FileSystemPath,
) -> Result<Vc<Box<dyn OutputAsset>>> {
let client_relative_path_ref = client_relative_path.clone();
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SerializedAppBuildManifest {
pub pages: FxIndexMap<RcStr, Vec<RcStr>>,
}
let pages: Vec<(RcStr, Vec<RcStr>)> = self
.pages
.iter()
.map(|(k, chunks)| {
let client_relative_path_ref = client_relative_path_ref.clone();
async move {
Ok((
k.clone(),
chunks
.await?
.iter()
.copied()
.map(|chunk| {
let client_relative_path_ref = client_relative_path_ref.clone();
async move {
let chunk_path = chunk.path().await?;
Ok(client_relative_path_ref
.get_path_to(&chunk_path)
.context(
"client chunk entry path must be inside the client \
root",
)?
.into())
}
})
.try_join()
.await?,
))
}
})
.try_join()
.await?;
let manifest = SerializedAppBuildManifest {
pages: FxIndexMap::from_iter(pages.into_iter()),
};
let references = self.pages.values().try_join().await?;
let references = references
.into_iter()
.flat_map(|c| c.into_iter().copied())
.collect();
Ok(Vc::upcast(VirtualOutputAsset::new_with_references(
output_path,
AssetContent::file(File::from(serde_json::to_string_pretty(&manifest)?).into()),
Vc::cell(references),
)))
}
}
// TODO(alexkirsz) Unify with the one for dev. // TODO(alexkirsz) Unify with the one for dev.
#[derive(Serialize, Debug)] #[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
......
...@@ -109,7 +109,6 @@ export async function handleRouteType({ ...@@ -109,7 +109,6 @@ export async function handleRouteType({
manifestLoader.deleteMiddlewareManifest(key) manifestLoader.deleteMiddlewareManifest(key)
} }
manifestLoader.loadAppBuildManifest(page)
manifestLoader.loadBuildManifest(page, 'app') manifestLoader.loadBuildManifest(page, 'app')
manifestLoader.loadAppPathsManifest(page) manifestLoader.loadAppPathsManifest(page)
manifestLoader.loadActionManifest(page) manifestLoader.loadActionManifest(page)
......
import type { AppBuildManifest } from './webpack/plugins/app-build-manifest-plugin'
import type { PagesManifest } from './webpack/plugins/pages-manifest-plugin' import type { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
import type { ExportPathMap, NextConfigComplete } from '../server/config-shared' import type { ExportPathMap, NextConfigComplete } from '../server/config-shared'
import type { MiddlewareManifest } from './webpack/plugins/middleware-plugin' import type { MiddlewareManifest } from './webpack/plugins/middleware-plugin'
...@@ -68,7 +67,6 @@ import { ...@@ -68,7 +67,6 @@ import {
MIDDLEWARE_MANIFEST, MIDDLEWARE_MANIFEST,
APP_PATHS_MANIFEST, APP_PATHS_MANIFEST,
APP_PATH_ROUTES_MANIFEST, APP_PATH_ROUTES_MANIFEST,
APP_BUILD_MANIFEST,
RSC_MODULE_TYPES, RSC_MODULE_TYPES,
NEXT_FONT_MANIFEST, NEXT_FONT_MANIFEST,
SUBRESOURCE_INTEGRITY_MANIFEST, SUBRESOURCE_INTEGRITY_MANIFEST,
...@@ -132,8 +130,6 @@ import createSpinner from './spinner' ...@@ -132,8 +130,6 @@ import createSpinner from './spinner'
import { trace, flushAllTraces, setGlobal, type Span } from '../trace' import { trace, flushAllTraces, setGlobal, type Span } from '../trace'
import { import {
detectConflictingPaths, detectConflictingPaths,
computeFromManifest,
getJsPageSizeInKb,
printCustomRoutes, printCustomRoutes,
printTreeView, printTreeView,
copyTracedFiles, copyTracedFiles,
...@@ -1840,7 +1836,6 @@ export default async function build( ...@@ -1840,7 +1836,6 @@ export default async function build(
const postCompileSpinner = createSpinner('Collecting page data') const postCompileSpinner = createSpinner('Collecting page data')
const buildManifestPath = path.join(distDir, BUILD_MANIFEST) const buildManifestPath = path.join(distDir, BUILD_MANIFEST)
const appBuildManifestPath = path.join(distDir, APP_BUILD_MANIFEST)
let staticAppPagesCount = 0 let staticAppPagesCount = 0
let serverAppPagesCount = 0 let serverAppPagesCount = 0
...@@ -1861,9 +1856,6 @@ export default async function build( ...@@ -1861,9 +1856,6 @@ export default async function build(
const pageInfos: PageInfos = new Map<string, PageInfo>() const pageInfos: PageInfos = new Map<string, PageInfo>()
let pagesManifest = await readManifest<PagesManifest>(pagesManifestPath) let pagesManifest = await readManifest<PagesManifest>(pagesManifestPath)
const buildManifest = await readManifest<BuildManifest>(buildManifestPath) const buildManifest = await readManifest<BuildManifest>(buildManifestPath)
const appBuildManifest = appDir
? await readManifest<AppBuildManifest>(appBuildManifestPath)
: undefined
const appPathRoutes: Record<string, string> = {} const appPathRoutes: Record<string, string> = {}
...@@ -1980,12 +1972,6 @@ export default async function build( ...@@ -1980,12 +1972,6 @@ export default async function build(
// eslint-disable-next-line @typescript-eslint/no-shadow // eslint-disable-next-line @typescript-eslint/no-shadow
let hasSsrAmpPages = false let hasSsrAmpPages = false
const computedManifestData = await computeFromManifest(
{ build: buildManifest, app: appBuildManifest },
distDir,
config.experimental.gzipSize
)
const middlewareManifest: MiddlewareManifest = require( const middlewareManifest: MiddlewareManifest = require(
path.join(distDir, SERVER_DIRECTORY, MIDDLEWARE_MANIFEST) path.join(distDir, SERVER_DIRECTORY, MIDDLEWARE_MANIFEST)
) )
...@@ -2043,15 +2029,6 @@ export default async function build( ...@@ -2043,15 +2029,6 @@ export default async function build(
}) })
return checkPageSpan.traceAsyncFn(async () => { return checkPageSpan.traceAsyncFn(async () => {
const actualPage = normalizePagePath(page) const actualPage = normalizePagePath(page)
const [size, totalSize] = await getJsPageSizeInKb(
pageType,
actualPage,
distDir,
buildManifest,
appBuildManifest,
config.experimental.gzipSize,
computedManifestData
)
let isRoutePPREnabled = false let isRoutePPREnabled = false
let isSSG = false let isSSG = false
...@@ -2412,8 +2389,6 @@ export default async function build( ...@@ -2412,8 +2389,6 @@ export default async function build(
pageInfos.set(page, { pageInfos.set(page, {
originalAppPath, originalAppPath,
size,
totalSize,
isStatic, isStatic,
isSSG, isSSG,
isRoutePPREnabled, isRoutePPREnabled,
...@@ -2547,7 +2522,6 @@ export default async function build( ...@@ -2547,7 +2522,6 @@ export default async function build(
: []), : []),
path.join(SERVER_DIRECTORY, APP_PATHS_MANIFEST), path.join(SERVER_DIRECTORY, APP_PATHS_MANIFEST),
path.join(APP_PATH_ROUTES_MANIFEST), path.join(APP_PATH_ROUTES_MANIFEST),
APP_BUILD_MANIFEST,
path.join( path.join(
SERVER_DIRECTORY, SERVER_DIRECTORY,
SERVER_REFERENCE_MANIFEST + '.js' SERVER_REFERENCE_MANIFEST + '.js'
...@@ -4162,15 +4136,11 @@ export default async function build( ...@@ -4162,15 +4136,11 @@ export default async function build(
await nextBuildSpan.traceChild('print-tree-view').traceAsyncFn(() => await nextBuildSpan.traceChild('print-tree-view').traceAsyncFn(() =>
printTreeView(pageKeys, pageInfos, { printTreeView(pageKeys, pageInfos, {
distPath: distDir,
buildId: buildId,
pagesDir, pagesDir,
useStaticPages404, useStaticPages404,
pageExtensions: config.pageExtensions, pageExtensions: config.pageExtensions,
appBuildManifest,
buildManifest, buildManifest,
middlewareManifest, middlewareManifest,
gzipSize: config.experimental.gzipSize,
}) })
) )
......
This diff is collapsed.
...@@ -63,7 +63,6 @@ import loadJsConfig, { ...@@ -63,7 +63,6 @@ import loadJsConfig, {
type ResolvedBaseUrl, type ResolvedBaseUrl,
} from './load-jsconfig' } from './load-jsconfig'
import { loadBindings } from './swc' import { loadBindings } from './swc'
import { AppBuildManifestPlugin } from './webpack/plugins/app-build-manifest-plugin'
import { SubresourceIntegrityPlugin } from './webpack/plugins/subresource-integrity-plugin' import { SubresourceIntegrityPlugin } from './webpack/plugins/subresource-integrity-plugin'
import { NextFontManifestPlugin } from './webpack/plugins/next-font-manifest-plugin' import { NextFontManifestPlugin } from './webpack/plugins/next-font-manifest-plugin'
import { getSupportedBrowsers } from './utils' import { getSupportedBrowsers } from './utils'
...@@ -1970,7 +1969,7 @@ export default async function getBaseWebpackConfig( ...@@ -1970,7 +1969,7 @@ export default async function getBaseWebpackConfig(
'.shared-runtime' '.shared-runtime'
) )
const layer = resource.contextInfo.issuerLayer const layer = resource.contextInfo.issuerLayer
let runtime let runtime: string
switch (layer) { switch (layer) {
case WEBPACK_LAYERS.serverSideRendering: case WEBPACK_LAYERS.serverSideRendering:
...@@ -2128,7 +2127,6 @@ export default async function getBaseWebpackConfig( ...@@ -2128,7 +2127,6 @@ export default async function getBaseWebpackConfig(
minimized: true, minimized: true,
}, },
}), }),
hasAppDir && isClient && new AppBuildManifestPlugin(),
hasAppDir && hasAppDir &&
(isClient (isClient
? new ClientReferenceManifestPlugin({ ? new ClientReferenceManifestPlugin({
......
import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import {
APP_BUILD_MANIFEST,
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP,
SYSTEM_ENTRYPOINTS,
} from '../../../shared/lib/constants'
import { getEntrypointFiles } from './build-manifest-plugin'
import getAppRouteFromEntrypoint from '../../../server/get-app-route-from-entrypoint'
export type AppBuildManifest = {
pages: Record<string, string[]>
}
const PLUGIN_NAME = 'AppBuildManifestPlugin'
export class AppBuildManifestPlugin {
public apply(compiler: any) {
compiler.hooks.make.tap(PLUGIN_NAME, (compilation: any) => {
compilation.hooks.processAssets.tap(
{
name: PLUGIN_NAME,
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
},
() => this.createAsset(compilation)
)
})
}
private createAsset(compilation: webpack.Compilation) {
const manifest: AppBuildManifest = {
pages: {},
}
const mainFiles = new Set(
getEntrypointFiles(
compilation.entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_MAIN_APP)
)
)
for (const entrypoint of compilation.entrypoints.values()) {
if (!entrypoint.name) {
continue
}
if (SYSTEM_ENTRYPOINTS.has(entrypoint.name)) {
continue
}
const pagePath = getAppRouteFromEntrypoint(entrypoint.name)
if (!pagePath) {
continue
}
const filesForPage = getEntrypointFiles(entrypoint)
manifest.pages[pagePath] = [...new Set([...mainFiles, ...filesForPage])]
}
const json = JSON.stringify(manifest, null, 2)
compilation.emitAsset(
APP_BUILD_MANIFEST,
new sources.RawSource(json) as unknown as webpack.sources.RawSource
)
}
}
...@@ -388,6 +388,8 @@ export interface ExperimentalConfig { ...@@ -388,6 +388,8 @@ export interface ExperimentalConfig {
skipValidation?: boolean skipValidation?: boolean
} }
disableOptimizedLoading?: boolean disableOptimizedLoading?: boolean
/** @deprecated A no-op as of Next 16, size metrics were removed from the build output. */
gzipSize?: boolean gzipSize?: boolean
craCompat?: boolean craCompat?: boolean
esmExternals?: boolean | 'loose' esmExternals?: boolean | 'loose'
......
...@@ -387,7 +387,6 @@ export async function handleRouteType({ ...@@ -387,7 +387,6 @@ export async function handleRouteType({
manifestLoader.deleteMiddlewareManifest(key) manifestLoader.deleteMiddlewareManifest(key)
} }
manifestLoader.loadAppBuildManifest(page)
manifestLoader.loadBuildManifest(page, 'app') manifestLoader.loadBuildManifest(page, 'app')
manifestLoader.loadAppPathsManifest(page) manifestLoader.loadAppPathsManifest(page)
manifestLoader.loadActionManifest(page) manifestLoader.loadActionManifest(page)
......
...@@ -181,7 +181,7 @@ async function loadComponentsImpl<N = any>({ ...@@ -181,7 +181,7 @@ async function loadComponentsImpl<N = any>({
// attempting to load. // attempting to load.
const manifestLoadAttempts = isDev ? 3 : 1 const manifestLoadAttempts = isDev ? 3 : 1
let reactLoadableManifestPath let reactLoadableManifestPath: string
if (!process.env.TURBOPACK) { if (!process.env.TURBOPACK) {
reactLoadableManifestPath = join( reactLoadableManifestPath = join(
/* turbopackIgnore: true */ distDir, /* turbopackIgnore: true */ distDir,
......
...@@ -87,7 +87,6 @@ export const WEBPACK_STATS = 'webpack-stats.json' ...@@ -87,7 +87,6 @@ export const WEBPACK_STATS = 'webpack-stats.json'
export const APP_PATHS_MANIFEST = 'app-paths-manifest.json' export const APP_PATHS_MANIFEST = 'app-paths-manifest.json'
export const APP_PATH_ROUTES_MANIFEST = 'app-path-routes-manifest.json' export const APP_PATH_ROUTES_MANIFEST = 'app-path-routes-manifest.json'
export const BUILD_MANIFEST = 'build-manifest.json' export const BUILD_MANIFEST = 'build-manifest.json'
export const APP_BUILD_MANIFEST = 'app-build-manifest.json'
export const FUNCTIONS_CONFIG_MANIFEST = 'functions-config-manifest.json' export const FUNCTIONS_CONFIG_MANIFEST = 'functions-config-manifest.json'
export const SUBRESOURCE_INTEGRITY_MANIFEST = 'subresource-integrity-manifest' export const SUBRESOURCE_INTEGRITY_MANIFEST = 'subresource-integrity-manifest'
export const NEXT_FONT_MANIFEST = 'next-font-manifest' export const NEXT_FONT_MANIFEST = 'next-font-manifest'
......
...@@ -10,13 +10,11 @@ import type { ...@@ -10,13 +10,11 @@ import type {
StatsCompilation as WebpackStats, StatsCompilation as WebpackStats,
} from 'webpack' } from 'webpack'
import type { BuildManifest } from '../../../server/get-page-files' import type { BuildManifest } from '../../../server/get-page-files'
import type { AppBuildManifest } from '../../../build/webpack/plugins/app-build-manifest-plugin'
import type { PagesManifest } from '../../../build/webpack/plugins/pages-manifest-plugin' import type { PagesManifest } from '../../../build/webpack/plugins/pages-manifest-plugin'
import type { ActionManifest } from '../../../build/webpack/plugins/flight-client-entry-plugin' import type { ActionManifest } from '../../../build/webpack/plugins/flight-client-entry-plugin'
import type { NextFontManifest } from '../../../build/webpack/plugins/next-font-manifest-plugin' import type { NextFontManifest } from '../../../build/webpack/plugins/next-font-manifest-plugin'
import type { REACT_LOADABLE_MANIFEST } from '../constants' import type { REACT_LOADABLE_MANIFEST } from '../constants'
import { import {
APP_BUILD_MANIFEST,
APP_PATHS_MANIFEST, APP_PATHS_MANIFEST,
BUILD_MANIFEST, BUILD_MANIFEST,
INTERCEPTION_ROUTE_REWRITE_MANIFEST, INTERCEPTION_ROUTE_REWRITE_MANIFEST,
...@@ -68,7 +66,6 @@ type TurbopackMiddlewareManifest = MiddlewareManifest & { ...@@ -68,7 +66,6 @@ type TurbopackMiddlewareManifest = MiddlewareManifest & {
type ManifestName = type ManifestName =
| typeof MIDDLEWARE_MANIFEST | typeof MIDDLEWARE_MANIFEST
| typeof BUILD_MANIFEST | typeof BUILD_MANIFEST
| typeof APP_BUILD_MANIFEST
| typeof PAGES_MANIFEST | typeof PAGES_MANIFEST
| typeof WEBPACK_STATS | typeof WEBPACK_STATS
| typeof APP_PATHS_MANIFEST | typeof APP_PATHS_MANIFEST
...@@ -134,7 +131,6 @@ function readPartialManifest<T>( ...@@ -134,7 +131,6 @@ function readPartialManifest<T>(
export class TurbopackManifestLoader { export class TurbopackManifestLoader {
private actionManifests: Map<EntryKey, ActionManifest> = new Map() private actionManifests: Map<EntryKey, ActionManifest> = new Map()
private appBuildManifests: Map<EntryKey, AppBuildManifest> = new Map()
private appPathsManifests: Map<EntryKey, PagesManifest> = new Map() private appPathsManifests: Map<EntryKey, PagesManifest> = new Map()
private buildManifests: Map<EntryKey, BuildManifest> = new Map() private buildManifests: Map<EntryKey, BuildManifest> = new Map()
private clientBuildManifests: Map<EntryKey, ClientBuildManifest> = new Map() private clientBuildManifests: Map<EntryKey, ClientBuildManifest> = new Map()
...@@ -164,7 +160,6 @@ export class TurbopackManifestLoader { ...@@ -164,7 +160,6 @@ export class TurbopackManifestLoader {
delete(key: EntryKey) { delete(key: EntryKey) {
this.actionManifests.delete(key) this.actionManifests.delete(key)
this.appBuildManifests.delete(key)
this.appPathsManifests.delete(key) this.appPathsManifests.delete(key)
this.buildManifests.delete(key) this.buildManifests.delete(key)
this.clientBuildManifests.delete(key) this.clientBuildManifests.delete(key)
...@@ -252,36 +247,6 @@ export class TurbopackManifestLoader { ...@@ -252,36 +247,6 @@ export class TurbopackManifestLoader {
) )
} }
loadAppBuildManifest(pageName: string): void {
this.appBuildManifests.set(
getEntryKey('app', 'server', pageName),
readPartialManifest(this.distDir, APP_BUILD_MANIFEST, pageName, 'app')
)
}
private mergeAppBuildManifests(manifests: Iterable<AppBuildManifest>) {
const manifest: AppBuildManifest = {
pages: {},
}
for (const m of manifests) {
Object.assign(manifest.pages, m.pages)
}
manifest.pages = sortObjectByKey(manifest.pages)
return manifest
}
private writeAppBuildManifest(): void {
const appBuildManifest = this.mergeAppBuildManifests(
this.appBuildManifests.values()
)
const appBuildManifestPath = join(this.distDir, APP_BUILD_MANIFEST)
deleteCache(appBuildManifestPath)
writeFileAtomic(
appBuildManifestPath,
JSON.stringify(appBuildManifest, null, 2)
)
}
loadAppPathsManifest(pageName: string): void { loadAppPathsManifest(pageName: string): void {
this.appPathsManifests.set( this.appPathsManifests.set(
getEntryKey('app', 'server', pageName), getEntryKey('app', 'server', pageName),
...@@ -765,7 +730,6 @@ export class TurbopackManifestLoader { ...@@ -765,7 +730,6 @@ export class TurbopackManifestLoader {
entrypoints: Entrypoints entrypoints: Entrypoints
}): void { }): void {
this.writeActionManifest() this.writeActionManifest()
this.writeAppBuildManifest()
this.writeAppPathsManifest() this.writeAppPathsManifest()
this.writeBuildManifest(entrypoints, devRewrites, productionRewrites) this.writeBuildManifest(entrypoints, devRewrites, productionRewrites)
this.writeFallbackBuildManifest() this.writeFallbackBuildManifest()
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('app-dir alias', () => { describe('app-dir alias', () => {
const { next, isNextStart, skipped } = nextTestSetup({ const { next, skipped } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true, skipDeployment: true,
}) })
...@@ -22,27 +22,4 @@ describe('app-dir alias', () => { ...@@ -22,27 +22,4 @@ describe('app-dir alias', () => {
.getComputedCss('font-size') .getComputedCss('font-size')
expect(fontSize).toBe('50px') expect(fontSize).toBe('50px')
}) })
if (isNextStart) {
it('should not contain installed react/react-dom version in client chunks', async () => {
const appBuildManifest = await next.readJSON(
'.next/app-build-manifest.json'
)
Object.keys(appBuildManifest.pages).forEach((page) => {
const containFrameworkChunk = appBuildManifest.pages[page].some(
(chunk) => {
return chunk.includes('framework')
}
)
expect(containFrameworkChunk).toBe(false)
})
})
it('should generate app-build-manifest correctly', async () => {
// Remove other page CSS files:
const manifest = await next.readJSON('.next/app-build-manifest.json')
expect(manifest.pages).not.toBeEmptyObject()
})
}
}) })
...@@ -79,14 +79,6 @@ describe('app dir - basic', () => { ...@@ -79,14 +79,6 @@ describe('app dir - basic', () => {
} }
if (isNextStart && !process.env.NEXT_EXPERIMENTAL_COMPILE) { if (isNextStart && !process.env.NEXT_EXPERIMENTAL_COMPILE) {
if (!process.env.NEXT_EXPERIMENTAL_COMPILE) {
it('should have correct size in build output', async () => {
expect(next.cliOutput).toMatch(
/\/dashboard\/another.*? *?[^0]\d{1,} [\w]{1,}B/
)
})
}
it('should have correct preferredRegion values in manifest', async () => { it('should have correct preferredRegion values in manifest', async () => {
const middlewareManifest = JSON.parse( const middlewareManifest = JSON.parse(
await next.readFile('.next/server/middleware-manifest.json') await next.readFile('.next/server/middleware-manifest.json')
......
'use client'
import React from 'react'
import styles from '../../styles/index.module.css'
export default function Page() {
return (
<>
<p id="hello" className={styles.content}>
hello from /foo
</p>
<p id="react-version">{React.version}</p>
</>
)
}
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import React from 'react'
import styles from '../styles/index.module.css'
export default function Page() {
return (
<>
<p id="hello" className={styles.content}>
hello from /
</p>
<p id="react-version">{React.version}</p>
</>
)
}
import { nextTestSetup } from 'e2e-utils'
describe('app-dir build size', () => {
const { next, isNextStart, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
if (isNextStart) {
it('should have correct size in build output', async () => {
const regex = /(\S+)\s+([\d.]+\s\w+)\s+([\d.]+\s\w+)/g
const matches = [...next.cliOutput.matchAll(regex)]
const result = matches.reduce((acc, match) => {
const [, path, size, firstLoadJS] = match
acc[path] = { size, firstLoadJS }
return acc
}, {})
// convert pretty-bytes format into bytes so we can compare units
const sizeToBytes = (size: string) => {
const units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const [value, unit] = size.split(' ', 2)
const exp = units.indexOf(unit)
return parseFloat(value) * Math.pow(1024, exp)
}
const index = result['/']
const foo = result['/foo']
expect(sizeToBytes(index.firstLoadJS)).toBeGreaterThan(0)
expect(sizeToBytes(foo.firstLoadJS)).toBeGreaterThan(0)
// index route is a page with no client JS, so it could serve zero additional JS (size = 0)
// foo route is a page with client references, so it has to serve additional non-shared JS
expect(sizeToBytes(foo.size)).toBeGreaterThan(0)
// foo has a client component, so it should be larger than index
expect(sizeToBytes(foo.size)).toBeGreaterThan(sizeToBytes(index.size))
})
} else {
it('should skip next dev for now', () => {})
return
}
})
...@@ -23,10 +23,10 @@ describe('Lazy Module Init', () => { ...@@ -23,10 +23,10 @@ describe('Lazy Module Init', () => {
throw new Error('expected build not to fail for fully static project') throw new Error('expected build not to fail for fully static project')
} }
expect(next.cliOutput).toContain('○ /server ') expect(next.cliOutput).toContain('○ /server')
expect(next.cliOutput).toContain('○ /client ') expect(next.cliOutput).toContain('○ /client')
expect(next.cliOutput).toContain('◐ /client-page ') expect(next.cliOutput).toContain('◐ /client-page')
expect(next.cliOutput).toContain('◐ /[dyn] ') expect(next.cliOutput).toContain('◐ /[dyn]')
let $ let $
$ = await next.render$('/server') $ = await next.render$('/server')
......
...@@ -848,7 +848,7 @@ describe('Cache Components Errors', () => { ...@@ -848,7 +848,7 @@ describe('Cache Components Errors', () => {
throw new Error('expected build not to fail', { cause: error }) throw new Error('expected build not to fail', { cause: error })
} }
expect(next.cliOutput).toContain(`◐ ${pathname} `) expect(next.cliOutput).toContain(`◐ ${pathname}`)
await next.start({ skipBuild: true }) await next.start({ skipBuild: true })
const $ = await next.render$(pathname) const $ = await next.render$(pathname)
expect($('[data-fallback]').length).toBe(2) expect($('[data-fallback]').length).toBe(2)
...@@ -1124,7 +1124,7 @@ describe('Cache Components Errors', () => { ...@@ -1124,7 +1124,7 @@ describe('Cache Components Errors', () => {
throw new Error('expected build not to fail', { cause: error }) throw new Error('expected build not to fail', { cause: error })
} }
expect(next.cliOutput).toContain(`◐ ${pathname} `) expect(next.cliOutput).toContain(`◐ ${pathname}`)
await next.start({ skipBuild: true }) await next.start({ skipBuild: true })
const browser = await next.browser(`${pathname}?foo=test`) const browser = await next.browser(`${pathname}?foo=test`)
expect(await browser.elementById('foo-param').text()).toBe( expect(await browser.elementById('foo-param').text()).toBe(
...@@ -1176,7 +1176,7 @@ describe('Cache Components Errors', () => { ...@@ -1176,7 +1176,7 @@ describe('Cache Components Errors', () => {
throw new Error('expected build not to fail', { cause: error }) throw new Error('expected build not to fail', { cause: error })
} }
expect(next.cliOutput).toContain(`◐ ${pathname} `) expect(next.cliOutput).toContain(`◐ ${pathname}`)
await next.start({ skipBuild: true }) await next.start({ skipBuild: true })
const browser = await next.browser(`${pathname}?foo=test`) const browser = await next.browser(`${pathname}?foo=test`)
expect(await browser.elementById('foo-param').text()).toBe( expect(await browser.elementById('foo-param').text()).toBe(
...@@ -1564,7 +1564,7 @@ describe('Cache Components Errors', () => { ...@@ -1564,7 +1564,7 @@ describe('Cache Components Errors', () => {
throw new Error('expected build not to fail', { cause: error }) throw new Error('expected build not to fail', { cause: error })
} }
expect(next.cliOutput).toContain(`◐ ${pathname} `) expect(next.cliOutput).toContain(`◐ ${pathname}`)
await next.start({ skipBuild: true }) await next.start({ skipBuild: true })
const browser = await next.browser(`${pathname}`) const browser = await next.browser(`${pathname}`)
expect(await browser.elementById('draft-mode').text()).toBe( expect(await browser.elementById('draft-mode').text()).toBe(
...@@ -1936,7 +1936,7 @@ describe('Cache Components Errors', () => { ...@@ -1936,7 +1936,7 @@ describe('Cache Components Errors', () => {
throw new Error('expected build not to fail', { cause: error }) throw new Error('expected build not to fail', { cause: error })
} }
expect(next.cliOutput).toContain(`◐ ${pathname}/[slug] `) expect(next.cliOutput).toContain(`◐ ${pathname}/[slug]`)
await next.start({ skipBuild: true }) await next.start({ skipBuild: true })
const browser = await next.browser(`${pathname}/test`) const browser = await next.browser(`${pathname}/test`)
expect(await browser.elementById('param').text()).toBe('undefined') expect(await browser.elementById('param').text()).toBe('undefined')
...@@ -1984,7 +1984,7 @@ describe('Cache Components Errors', () => { ...@@ -1984,7 +1984,7 @@ describe('Cache Components Errors', () => {
throw new Error('expected build not to fail', { cause: error }) throw new Error('expected build not to fail', { cause: error })
} }
expect(next.cliOutput).toContain(`◐ ${pathname}/[slug] `) expect(next.cliOutput).toContain(`◐ ${pathname}/[slug]`)
await next.start({ skipBuild: true }) await next.start({ skipBuild: true })
const browser = await next.browser(`${pathname}/test`) const browser = await next.browser(`${pathname}/test`)
expect(await browser.elementById('param').text()).toBe('undefined') expect(await browser.elementById('param').text()).toBe('undefined')
......
...@@ -45,10 +45,7 @@ describe('Build Output', () => { ...@@ -45,10 +45,7 @@ describe('Build Output', () => {
} }
it('should not include internal pages', async () => { it('should not include internal pages', async () => {
expect(stdout).toMatch(/\/ (.* )?\d{1,} k?B/) expect(stdout).toMatch(/\//)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/.*\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/.*\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain(' /_document') expect(stdout).not.toContain(' /_document')
expect(stdout).not.toContain(' /_app') expect(stdout).not.toContain(' /_app')
...@@ -206,10 +203,8 @@ describe('Build Output', () => { ...@@ -206,10 +203,8 @@ describe('Build Output', () => {
stdout: true, stdout: true,
}) })
expect(stdout).toMatch(/\/ (.* )?\d{1,} k?B/) expect(stdout).toMatch(/\//)
expect(stdout).toMatch(/\/_app (.* )?\d{1,} k?B/) expect(stdout).toMatch(/\/_app/)
expect(stdout).toMatch(/\+ First Load JS shared by all \s*[0-9.]+ kB/)
expect(stdout).toMatch(/ chunks\/.*\.js \s*[0-9.]+ kB/)
expect(stdout).not.toContain(' /_document') expect(stdout).not.toContain(' /_document')
expect(stdout).not.toContain(' /_error') expect(stdout).not.toContain(' /_error')
...@@ -235,13 +230,9 @@ describe('Build Output', () => { ...@@ -235,13 +230,9 @@ describe('Build Output', () => {
stdout: true, stdout: true,
}) })
expect(stdout).toMatch(/\/ (.* )?[0-9.]+ k?B \s*[0-9.]+ kB/) expect(stdout).toMatch(/\//)
expect(stdout).toMatch(/\/amp (.* )?AMP/) expect(stdout).toMatch(/\/amp (.* )?AMP/)
expect(stdout).toMatch(/\/hybrid (.* )?[0-9.]+ k?B/) expect(stdout).toMatch(/\/hybrid (.* )?/)
expect(stdout).toMatch(
/\+ First Load JS shared by all \s*[0-9.]+ kB/
)
expect(stdout).toMatch(/ chunks\/.*\.js \s*[0-9.]+ kB/)
expect(stdout).not.toContain(' /_document') expect(stdout).not.toContain(' /_document')
expect(stdout).not.toContain(' /_error') expect(stdout).not.toContain(' /_error')
...@@ -264,10 +255,8 @@ describe('Build Output', () => { ...@@ -264,10 +255,8 @@ describe('Build Output', () => {
stdout: true, stdout: true,
}) })
expect(stdout).toMatch(/\/ (.* )?\d{1,} k?B/) expect(stdout).toMatch(/\//)
expect(stdout).toMatch(/ƒ \/404 (.* )?\d{1,} k?B/) expect(stdout).toMatch(/ƒ \/404/)
expect(stdout).toMatch(/\+ First Load JS shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/.*\.js [ 0-9.]* kB/)
expect(stdout).not.toContain(' /_document') expect(stdout).not.toContain(' /_document')
expect(stdout).not.toContain(' /_app') expect(stdout).not.toContain(' /_app')
...@@ -303,7 +292,7 @@ describe('Build Output', () => { ...@@ -303,7 +292,7 @@ describe('Build Output', () => {
stdout: true, stdout: true,
}) })
expect(stdout.match(/○ \/root-page /g).length).toBe(1) expect(stdout.match(/○ \/root-page/g).length).toBe(1)
}) })
}) })
} }
......
...@@ -43,7 +43,6 @@ describe('Basic CSS Module Support', () => { ...@@ -43,7 +43,6 @@ describe('Basic CSS Module Support', () => {
it('should have compiled successfully', () => { it('should have compiled successfully', () => {
expect(code).toBe(0) expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/) expect(stdout).toMatch(/Compiled successfully/)
expect(stdout).toContain('.css')
}) })
it(`should've emitted a single CSS file`, async () => { it(`should've emitted a single CSS file`, async () => {
......
...@@ -3,16 +3,15 @@ ...@@ -3,16 +3,15 @@
import { remove } from 'fs-extra' import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils' import { nextBuild } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
import { readFileSync, statSync } from 'fs'
const fixturesDir = join(__dirname, '..', 'fixtures') const fixturesDir = join(__dirname, '..', 'fixtures')
const isRspack = process.env.NEXT_RSPACK !== undefined
describe('Fallback Modules', () => { describe('Fallback Modules', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)( ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode', 'production mode',
() => { () => {
describe('Crypto Application', () => { describe('Crypto Application', () => {
let stdout
const appDir = join(fixturesDir, 'with-crypto') const appDir = join(fixturesDir, 'with-crypto')
beforeAll(async () => { beforeAll(async () => {
...@@ -24,40 +23,44 @@ describe('Fallback Modules', () => { ...@@ -24,40 +23,44 @@ describe('Fallback Modules', () => {
return return
} }
;({ stdout } = await nextBuild(appDir, [], { await nextBuild(appDir, [], {
stdout: true, stdout: true,
})) })
console.log(stdout) // Read build manifest to get chunk files for the index page
const buildManifestPath = join(appDir, '.next', 'build-manifest.json')
const buildManifest = JSON.parse(
readFileSync(buildManifestPath, 'utf8')
)
const parsePageSize = (page) => // Get chunks for the '/' page
stdout.match( const indexPageChunks = buildManifest.pages['/'] || []
new RegExp(` ${page} .*?((?:\\d|\\.){1,} (?:\\w{1,})) `)
)[1]
const parsePageFirstLoad = (page) => // Calculate total size of all chunks for the index page
stdout.match( let totalSize = 0
new RegExp( for (const chunkPath of indexPageChunks) {
` ${page} .*?(?:(?:\\d|\\.){1,}) .*? ((?:\\d|\\.){1,} (?:\\w{1,}))` const fullChunkPath = join(appDir, '.next', chunkPath)
) try {
)[1] const stats = statSync(fullChunkPath)
totalSize += stats.size
} catch (error) {
console.warn(`Could not read chunk: ${chunkPath}`, error.message)
}
}
const indexSize = parsePageSize('/') // Convert to kB for easier comparison
const indexFirstLoad = parsePageFirstLoad('/') const totalSizeKB = totalSize / 1024
// expect(parseFloat(indexSize)).toBeLessThanOrEqual(3.1) console.log(`Index page total size: ${totalSizeKB.toFixed(2)} kB`)
// expect(parseFloat(indexSize)).toBeGreaterThanOrEqual(2) console.log(`Index page chunks: ${indexPageChunks.join(', ')}`)
if (isRspack) { // Assert on reasonable size bounds
expect(indexSize.endsWith('B')).toBe(true) // The total should be reasonable for a simple page without crypto
expect(indexSize.endsWith('MB')).toBe(false) expect(totalSizeKB).toBeGreaterThan(10) // At least 10kB (has some framework code)
} else { expect(totalSizeKB).toBeLessThan(400) // Less than 400kB (no large crypto libraries)
expect(indexSize.endsWith('kB')).toBe(true)
}
// expect(parseFloat(indexFirstLoad)).toBeLessThanOrEqual(67.9) // Ensure we have the expected chunks
// expect(parseFloat(indexFirstLoad)).toBeGreaterThanOrEqual(60) expect(indexPageChunks.length).toBeGreaterThan(0)
expect(indexFirstLoad.endsWith('kB')).toBe(true)
}) })
}) })
} }
......
...@@ -2,6 +2,7 @@ import { promises as fs } from 'fs' ...@@ -2,6 +2,7 @@ import { promises as fs } from 'fs'
import { join } from 'path' import { join } from 'path'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
import { ClientReferenceManifest } from 'next/dist/build/webpack/plugins/flight-manifest-plugin'
function getServerReferenceIdsFromBundle(source: string): string[] { function getServerReferenceIdsFromBundle(source: string): string[] {
// Reference IDs are strings with [0-9a-f] that are at least 32 characters long. // Reference IDs are strings with [0-9a-f] that are at least 32 characters long.
...@@ -29,16 +30,54 @@ describe('app-dir - client-actions-tree-shaking', () => { ...@@ -29,16 +30,54 @@ describe('app-dir - client-actions-tree-shaking', () => {
logs.length = 0 logs.length = 0
}) })
/**
* Parses the client reference manifest for a given route and returns the client chunks
*/
function getClientChunks(appDir: string, route: string): Array<string> {
const modulePath = require.resolve(
join(appDir, `.next/server/app/${route}_client-reference-manifest.js`)
)
require(modulePath)
const clientManfiest = globalThis.__RSC_MANIFEST[
route
] as ClientReferenceManifest
delete globalThis.__RSC_MANIFEST[route]
delete require.cache[modulePath]
const chunks = new Set<string>()
if (process.env.IS_TURBOPACK_TEST) {
// These only exist for turbopack and are encoded as files
// entryJSFiles is a map of moduel name to a set of chunks relative to `.next`
for (const entries of Object.values(clientManfiest.entryJSFiles)) {
for (const chunk of entries) {
chunks.add(chunk)
}
}
// client mmodules is a mapping from module name to a set of chunks releative to `/_next/`
// So strip that prefix and add it to the chunks
for (const clientModule of Object.values(clientManfiest.clientModules)) {
for (const chunk of clientModule.chunks) {
chunks.add(chunk.replace('/_next/', ''))
}
}
} else {
// webpack doens't use entryJSFiles, so we need to use clientModules but the format is different.
// chunks is a sequence of 'chunk-id', chunk-path pairs, so we need to skip the chunk-id
for (const clientModule of Object.values(clientManfiest.clientModules)) {
for (let i = 1; i < clientModule.chunks.length; i += 2) {
chunks.add(clientModule.chunks[i])
}
}
}
return Array.from(chunks)
}
it('should not bundle unused server reference id in client bundles', async () => { it('should not bundle unused server reference id in client bundles', async () => {
const appDir = next.testDir const appDir = next.testDir
const appBuildManifest = require( const bundle1Files = getClientChunks(appDir, '/route-1/page')
join(appDir, '.next/app-build-manifest.json') const bundle2Files = getClientChunks(appDir, '/route-2/page')
) const bundle3Files = getClientChunks(appDir, '/route-3/page')
const bundle1Files = appBuildManifest.pages['/route-1/page']
const bundle2Files = appBuildManifest.pages['/route-2/page']
const bundle3Files = appBuildManifest.pages['/route-3/page']
const bundle1Contents = await Promise.all( const bundle1Contents = await Promise.all(
bundle1Files.map((file: string) => bundle1Files.map((file: string) =>
......
...@@ -15,27 +15,25 @@ describe('build-output-tree-view', () => { ...@@ -15,27 +15,25 @@ describe('build-output-tree-view', () => {
it('should show info about prerendered and dynamic routes in a tree view', async () => { it('should show info about prerendered and dynamic routes in a tree view', async () => {
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(` expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(`
"Route (app) Size First Load JS Revalidate Expire "Route (app) Revalidate Expire
┌ ○ /_not-found N/A kB N/A kB ┌ ○ /_not-found
├ ƒ /api N/A kB N/A kB ├ ƒ /api
├ ○ /api/force-static N/A kB N/A kB ├ ○ /api/force-static
├ ○ /app-static N/A kB N/A kB ├ ○ /app-static
├ ○ /cache-life-custom N/A kB N/A kB ≈7m ≈2h ├ ○ /cache-life-custom ≈7m ≈2h
├ ○ /cache-life-hours N/A kB N/A kB 1h 1d ├ ○ /cache-life-hours 1h 1d
├ ƒ /dynamic N/A kB N/A kB ├ ƒ /dynamic
├ ◐ /ppr/[slug] N/A kB N/A kB 1w 30d ├ ◐ /ppr/[slug] 1w 30d
├ ├ /ppr/[slug] 1w 30d ├ ├ /ppr/[slug] 1w 30d
├ ├ /ppr/days 1d 1w ├ ├ /ppr/days 1d 1w
├ └ /ppr/weeks 1w 30d ├ └ /ppr/weeks 1w 30d
└ ○ /revalidate N/A kB N/A kB 15m 1y └ ○ /revalidate 15m 1y
+ First Load JS shared by all N/A kB
Route (pages) Size First Load JS Revalidate Expire Route (pages) Revalidate Expire
┌ ƒ /api/hello N/A kB N/A kB ┌ ƒ /api/hello
├ ● /gsp-revalidate N/A kB N/A kB 5m 1y ├ ● /gsp-revalidate 5m 1y
├ ƒ /gssp N/A kB N/A kB ├ ƒ /gssp
└ ○ /static N/A kB N/A kB └ ○ /static
+ First Load JS shared by all N/A kB
○ (Static) prerendered as static content ○ (Static) prerendered as static content
● (SSG) prerendered as static HTML (uses generateStaticParams) ● (SSG) prerendered as static HTML (uses generateStaticParams)
...@@ -58,14 +56,12 @@ describe('build-output-tree-view', () => { ...@@ -58,14 +56,12 @@ describe('build-output-tree-view', () => {
it('should show info about prerendered routes in a compact tree view', async () => { it('should show info about prerendered routes in a compact tree view', async () => {
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(` expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(`
"Route (app) Size First Load JS "Route (app)
┌ ○ / N/A kB N/A kB ┌ ○ /
└ ○ /_not-found N/A kB N/A kB └ ○ /_not-found
+ First Load JS shared by all N/A kB
Route (pages) Size First Load JS Route (pages)
─ ○ /static N/A kB N/A kB ─ ○ /static
+ First Load JS shared by all N/A kB
○ (Static) prerendered as static content" ○ (Static) prerendered as static content"
`) `)
......
...@@ -31,11 +31,6 @@ describe('production - app dir - build output', () => { ...@@ -31,11 +31,6 @@ describe('production - app dir - build output', () => {
}) })
it('should match the expected output format', async () => { it('should match the expected output format', async () => {
expect(output).toContain('Size')
expect(output).toContain('First Load JS')
expect(output).toContain('+ First Load JS shared by all')
expect(output).toContain('└ other shared chunks (total)')
// output type // output type
expect(output).toContain('○ (Static) prerendered as static content') expect(output).toContain('○ (Static) prerendered as static content')
}) })
......
import { createNext } from 'e2e-utils' import { createNext } from 'e2e-utils'
import { NextInstance } from 'e2e-utils' import type { NextInstance } from 'e2e-utils'
import { statSync } from 'fs'
import { join } from 'path'
// TODO: Implement experimental.fallbackNodePolyfills // TODO: Implement experimental.fallbackNodePolyfills
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)( ;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
...@@ -7,10 +9,28 @@ import { NextInstance } from 'e2e-utils' ...@@ -7,10 +9,28 @@ import { NextInstance } from 'e2e-utils'
() => { () => {
let next: NextInstance let next: NextInstance
function getFirstLoadSize(output: string) { async function getIndexPageSize() {
const firstLoadRe = // Read build manifest to get chunk files for the index page
/○ \/.*? (?<size>\d.*?) [^\d]{2} (?<firstLoad>\d.*?) [^\d]{2}/ // this only works reliably for pages router and simple examples.
return Number(output.match(firstLoadRe).groups.firstLoad) const buildManifest = await next.readJSON('.next/build-manifest.json')
// Get chunks for the '/' page
const indexPageChunks = buildManifest.pages['/'] || []
// Calculate total size of all chunks for the index page
let totalSize = 0
for (const chunkPath of indexPageChunks) {
const fullChunkPath = join(next.testDir, '.next', chunkPath)
try {
const stats = statSync(fullChunkPath)
totalSize += stats.size
} catch (error) {
console.warn(`Could not read chunk: ${chunkPath}`, error.message)
}
}
// Convert to kB for easier comparison
return totalSize / 1024
} }
beforeAll(async () => { beforeAll(async () => {
...@@ -37,7 +57,11 @@ import { NextInstance } from 'e2e-utils' ...@@ -37,7 +57,11 @@ import { NextInstance } from 'e2e-utils'
afterAll(() => next.destroy()) afterAll(() => next.destroy())
it('Fallback polyfills added by default', async () => { it('Fallback polyfills added by default', async () => {
expect(getFirstLoadSize(next.cliOutput)).not.toBeLessThan(200) const indexPageSizeKB = await getIndexPageSize()
console.log(
`Index page size (with polyfills): ${indexPageSizeKB.toFixed(2)} kB`
)
expect(indexPageSizeKB).not.toBeLessThan(400)
}) })
it('Reduced bundle size when polyfills are disabled', async () => { it('Reduced bundle size when polyfills are disabled', async () => {
...@@ -52,7 +76,11 @@ import { NextInstance } from 'e2e-utils' ...@@ -52,7 +76,11 @@ import { NextInstance } from 'e2e-utils'
await next.start() await next.start()
await next.stop() await next.stop()
expect(getFirstLoadSize(next.cliOutput)).toBeLessThan(200) const indexPageSizeKB = await getIndexPageSize()
console.log(
`Index page size (without polyfills): ${indexPageSizeKB.toFixed(2)} kB`
)
expect(indexPageSizeKB).toBeLessThan(400)
}) })
it('Pass build without error if non-polyfilled module is unreachable', async () => { it('Pass build without error if non-polyfilled module is unreachable', async () => {
......
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