-
Notifications
You must be signed in to change notification settings - Fork 26.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: build stats should properly report root page size in appDir #51854
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just personal recommendation for code modularity: