Skip to content

Commit c93f391

Browse files
committed
[dynamicIO] log dynamic validation errors consistently in dev
In dev when dynamicIO is enabled we performa 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 suprressed 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.
1 parent 51f88ce commit c93f391

File tree

2 files changed

+5
-5
lines changed
  • packages/next/src/server/app-render
  • test/e2e/app-dir/dynamic-io-errors/fixtures/dynamic-metadata-dynamic-route/app

2 files changed

+5
-5
lines changed

packages/next/src/server/app-render/dynamic-rendering.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,9 @@ export function throwIfDisallowedEmptyStaticShell(
691691
// you need to opt into that by adding a Suspense boundary above the body
692692
// to indicate your are ok with fully dynamic rendering.
693693
if (dynamicValidation.hasDynamicViewport) {
694-
throw new StaticGenBailoutError(
694+
console.error(
695695
`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`
696696
)
697+
throw new StaticGenBailoutError()
697698
}
698699
}

test/e2e/app-dir/dynamic-io-errors/fixtures/dynamic-metadata-dynamic-route/app/page.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ export default async function Page() {
99
return (
1010
<>
1111
<p>
12-
This page is static except for generateMetadata which does some IO. This
13-
is a build error because metadata is not wrapped in a Suspense boundary.
14-
We expect that if you intended for your metadata to be dynamic you will
15-
ensure your page is dynamic too
12+
This page has dynamic content and generateMetadata is also dynamic.
13+
generateMetadata being dynamic in this context is fine because it isn't
14+
the only reason the page is dynamic.
1615
</p>
1716
<Suspense fallback={<Fallback />}>
1817
<Dynamic />

0 commit comments

Comments
 (0)