Skip to content

Commit

Permalink
fix: show asPath on large page data warning (#39071)
Browse files Browse the repository at this point in the history
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: JJ Kasper <22380829+ijjk@users.noreply.github.com>
  • Loading branch information
balazsorban44 and ijjk committed Jul 27, 2022
1 parent 0a781dd commit 34f5236
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/next/pages/_document.tsx
Expand Up @@ -978,7 +978,11 @@ export class NextScript extends Component<OriginProps> {

if (largePageDataBytes && bytes > largePageDataBytes) {
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
)} which exceeds the threshold of ${prettyBytes(
largePageDataBytes
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/prerender.test.ts
Expand Up @@ -198,6 +198,11 @@ describe('Prerender', () => {
initialRevalidateSeconds: 1,
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': {
dataRoute: `/_next/data/${next.buildId}/blocking-fallback/test-errors-1.json`,
initialRevalidateSeconds: 1,
Expand Down Expand Up @@ -962,6 +967,11 @@ describe('Prerender', () => {
() => 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/
)
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) {
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/prerender/pages/blocking-fallback/[slug].js
Expand Up @@ -10,12 +10,23 @@ export async function getStaticPaths() {
{
params: { slug: 'test-errors-1' },
},
{
params: { slug: 'lots-of-data' },
},
],
fallback: 'blocking',
}
}

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')) {
const errorFile = path.join(process.cwd(), 'error.txt')
if (fs.existsSync(errorFile)) {
Expand Down

0 comments on commit 34f5236

Please sign in to comment.