Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: build stats should properly report root page size in appDir (#51854
) ### What? `next build` is incorrectly reporting file size stats for the root path when using the app dir ### Why? In #50768, the denormalization logic was removed for appDir routes, but `pagesManifest` has the root page keyed by `/` while the actual path will be `/index`. ### How? This re-adds a simpler denormalize function that just replaces `/index` with `/`. semi-related: #42819 Fixes #51692 link NEXT-1306 --------- Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: Jiachi Liu <inbox@huozhi.im>
- Loading branch information
1 parent
d06bc5e
commit aec75c2
Showing
7 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/next/src/shared/lib/page-path/denormalize-app-path.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function denormalizeAppPagePath(page: string): string { | ||
// `/` is normalized to `/index` | ||
if (page === '/index') { | ||
return '/' | ||
} | ||
|
||
return page | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'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> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'app-dir build size', | ||
{ | ||
files: __dirname, | ||
skipDeployment: true, | ||
}, | ||
({ next, isNextStart }) => { | ||
if (isNextStart) { | ||
it('should have correct size in build output', async () => { | ||
const regex = /(\S+)\s+(\d+\s\w+)\s+(\d+\.\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(' ') | ||
const exp = units.indexOf(unit) | ||
return parseFloat(value) * Math.pow(1024, exp) | ||
} | ||
|
||
const index = result['/'] | ||
const foo = result['/foo'] | ||
|
||
// index route has a page, so it should not be 0 | ||
expect(sizeToBytes(index.size)).toBeGreaterThan(0) | ||
expect(sizeToBytes(index.firstLoadJS)).toBeGreaterThan(0) | ||
|
||
// foo route has a page, so it should not be 0 | ||
expect(sizeToBytes(foo.size)).toBeGreaterThan(0) | ||
expect(sizeToBytes(foo.firstLoadJS)).toBeGreaterThan(0) | ||
|
||
// foo is 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 | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.content { | ||
color: blueviolet; | ||
} |