Unverified Commit 34f5236f authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

fix: show `asPath` on large page data warning (#39071)

Fixes #39057

Will now show:
```
Warning: data for page "/[[...slug]]" (path "/some-page") is 256 kB which exceeds the threshold of 128 kB, this amount of data can reduce performance.
See more info here: https://nextjs.org/docs/messages/large-page-data
```

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 0a781dd6
...@@ -978,7 +978,11 @@ export class NextScript extends Component<OriginProps> { ...@@ -978,7 +978,11 @@ export class NextScript extends Component<OriginProps> {
if (largePageDataBytes && bytes > largePageDataBytes) { if (largePageDataBytes && bytes > largePageDataBytes) {
console.warn( console.warn(
`Warning: data for page "${__NEXT_DATA__.page}" is ${prettyBytes( `Warning: data for page "${__NEXT_DATA__.page}"${
__NEXT_DATA__.page === context.dangerousAsPath
? ''
: ` (path "${context.dangerousAsPath}")`
} is ${prettyBytes(
bytes bytes
)} which exceeds the threshold of ${prettyBytes( )} which exceeds the threshold of ${prettyBytes(
largePageDataBytes largePageDataBytes
......
...@@ -198,6 +198,11 @@ describe('Prerender', () => { ...@@ -198,6 +198,11 @@ describe('Prerender', () => {
initialRevalidateSeconds: 1, initialRevalidateSeconds: 1,
srcRoute: '/blocking-fallback-some/[slug]', srcRoute: '/blocking-fallback-some/[slug]',
}, },
'/blocking-fallback/lots-of-data': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback/lots-of-data.json`,
initialRevalidateSeconds: false,
srcRoute: '/blocking-fallback/[slug]',
},
'/blocking-fallback/test-errors-1': { '/blocking-fallback/test-errors-1': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback/test-errors-1.json`, dataRoute: `/_next/data/${next.buildId}/blocking-fallback/test-errors-1.json`,
initialRevalidateSeconds: 1, initialRevalidateSeconds: 1,
...@@ -962,6 +967,11 @@ describe('Prerender', () => { ...@@ -962,6 +967,11 @@ describe('Prerender', () => {
() => next.cliOutput, () => next.cliOutput,
/Warning: data for page "\/large-page-data" is 256 kB which exceeds the threshold of 128 kB, this amount of data can reduce performance/ /Warning: data for page "\/large-page-data" is 256 kB which exceeds the threshold of 128 kB, this amount of data can reduce performance/
) )
await renderViaHTTP(next.url, '/blocking-fallback/lots-of-data')
await check(
() => next.cliOutput,
/Warning: data for page "\/blocking-fallback\/\[slug\]" \(path "\/blocking-fallback\/lots-of-data"\) is 256 kB which exceeds the threshold of 128 kB, this amount of data can reduce performance/
)
}) })
if ((global as any).isNextDev) { if ((global as any).isNextDev) {
......
...@@ -10,12 +10,23 @@ export async function getStaticPaths() { ...@@ -10,12 +10,23 @@ export async function getStaticPaths() {
{ {
params: { slug: 'test-errors-1' }, params: { slug: 'test-errors-1' },
}, },
{
params: { slug: 'lots-of-data' },
},
], ],
fallback: 'blocking', fallback: 'blocking',
} }
} }
export async function getStaticProps({ params }) { export async function getStaticProps({ params }) {
if (params.slug === 'lots-of-data') {
return {
props: {
lotsOfData: new Array(256 * 1000).fill('a').join(''),
},
}
}
if (params.slug.startsWith('test-errors')) { if (params.slug.startsWith('test-errors')) {
const errorFile = path.join(process.cwd(), 'error.txt') const errorFile = path.join(process.cwd(), 'error.txt')
if (fs.existsSync(errorFile)) { if (fs.existsSync(errorFile)) {
......
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