From cf7d360f86fd9543a0b513fd462cb9dc63344714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Wed, 27 Jul 2022 15:37:58 +0200 Subject: [PATCH 1/2] fix: show `asPath` on large page data warning --- packages/next/pages/_document.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx index 3086c431568c..a5e24bed21dc 100644 --- a/packages/next/pages/_document.tsx +++ b/packages/next/pages/_document.tsx @@ -978,7 +978,11 @@ export class NextScript extends Component { 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 From 5c0b6d34d510f6522aa1a0615dbe85cd87033a1e Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 27 Jul 2022 09:17:25 -0500 Subject: [PATCH 2/2] Add test case for updated message --- test/e2e/prerender.test.ts | 10 ++++++++++ test/e2e/prerender/pages/blocking-fallback/[slug].js | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/e2e/prerender.test.ts b/test/e2e/prerender.test.ts index ed06c391e93e..35e4d9acdebd 100644 --- a/test/e2e/prerender.test.ts +++ b/test/e2e/prerender.test.ts @@ -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, @@ -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) { diff --git a/test/e2e/prerender/pages/blocking-fallback/[slug].js b/test/e2e/prerender/pages/blocking-fallback/[slug].js index cf6aec867a32..af957a3c98f8 100644 --- a/test/e2e/prerender/pages/blocking-fallback/[slug].js +++ b/test/e2e/prerender/pages/blocking-fallback/[slug].js @@ -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)) {