Unverified Commit 784a9c86 authored by Josh Story's avatar Josh Story Committed by GitHub

[dynamicIO] log dynamic validation errors consistently in dev (#78575)

In dev when dynamicIO is enabled we perform a validating prerender to
look for code that would be a build error in `next build`. However due
to the construction of the earlier implementation of this code some
validation messages were being suppressed because they were conveyed as
a thrown error rather than through console.error. This change updates
the mechanism by which we raise these issues in dev so they are
consistently messaged.

stacked on #78574
parent 6b6782bc
...@@ -691,8 +691,9 @@ export function throwIfDisallowedEmptyStaticShell( ...@@ -691,8 +691,9 @@ export function throwIfDisallowedEmptyStaticShell(
// you need to opt into that by adding a Suspense boundary above the body // you need to opt into that by adding a Suspense boundary above the body
// to indicate your are ok with fully dynamic rendering. // to indicate your are ok with fully dynamic rendering.
if (dynamicValidation.hasDynamicViewport) { if (dynamicValidation.hasDynamicViewport) {
throw new StaticGenBailoutError( console.error(
`Route "${route}" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport` `Route "${route}" has a \`generateViewport\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport`
) )
throw new StaticGenBailoutError()
} }
} }
...@@ -257,10 +257,10 @@ function runTests(options: { withMinification: boolean }) { ...@@ -257,10 +257,10 @@ function runTests(options: { withMinification: boolean }) {
} }
const expectError = createExpectError(next.cliOutput) const expectError = createExpectError(next.cliOutput)
expectError('Error occurred prerendering page "/"')
expectError( expectError(
'Route "/" has a `generateViewport` that depends on Request data (`cookies()`, etc...) or uncached external data (`fetch(...)`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport' 'Route "/" has a `generateViewport` that depends on Request data (`cookies()`, etc...) or uncached external data (`fetch(...)`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport'
) )
expectError('Error occurred prerendering page "/"')
}) })
}) })
...@@ -299,10 +299,10 @@ function runTests(options: { withMinification: boolean }) { ...@@ -299,10 +299,10 @@ function runTests(options: { withMinification: boolean }) {
} }
const expectError = createExpectError(next.cliOutput) const expectError = createExpectError(next.cliOutput)
expectError('Error occurred prerendering page "/"')
expectError( expectError(
'Route "/" has a `generateViewport` that depends on Request data (`cookies()`, etc...) or uncached external data (`fetch(...)`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport' 'Route "/" has a `generateViewport` that depends on Request data (`cookies()`, etc...) or uncached external data (`fetch(...)`, etc...) without explicitly allowing fully dynamic rendering. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-viewport'
) )
expectError('Error occurred prerendering page "/"')
}) })
}) })
......
...@@ -9,10 +9,9 @@ export default async function Page() { ...@@ -9,10 +9,9 @@ export default async function Page() {
return ( return (
<> <>
<p> <p>
This page is static except for generateMetadata which does some IO. This This page has dynamic content and generateMetadata is also dynamic.
is a build error because metadata is not wrapped in a Suspense boundary. generateMetadata being dynamic in this context is fine because it isn't
We expect that if you intended for your metadata to be dynamic you will the only reason the page is dynamic.
ensure your page is dynamic too
</p> </p>
<Suspense fallback={<Fallback />}> <Suspense fallback={<Fallback />}>
<Dynamic /> <Dynamic />
......
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