You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prevent "use cache" timeout errors from being caught in userland code (#78998)
When `dynamicIO` is enabled and a `"use cache"` function accesses
dynamic request APIs, we fail the prerendering with a timeout error
after 50 seconds.
This error could be swallowed in userland code however, when the cached
function is wrapped in a try/catch block. That's not the intended
behavior, so we now fail the prerendering (or dynamic validation in dev
mode) with the timeout error in this case as well, using the same
approach as in #77838.
This also works around a bug that led to the timeout errors not being
source-mapped correctly with Turbopack.
In a future PR, we will adapt the behaviour for prerendering of fallback
shells that are allowed to be empty, in which case the timeout must not
fail the build.
Copy file name to clipboardExpand all lines: packages/next/src/server/app-render/dynamic-rendering.ts
+8-3
Original file line number
Diff line number
Diff line change
@@ -651,12 +651,17 @@ function createErrorWithComponentStack(
651
651
}
652
652
653
653
exportfunctionthrowIfDisallowedDynamic(
654
-
route: string,
654
+
workStore: WorkStore,
655
655
hasEmptyShell: boolean,
656
656
dynamicValidation: DynamicValidationState,
657
657
serverDynamic: DynamicTrackingState,
658
658
clientDynamic: DynamicTrackingState
659
659
): void{
660
+
if(workStore.invalidDynamicUsageError){
661
+
console.error(workStore.invalidDynamicUsageError)
662
+
thrownewStaticGenBailoutError()
663
+
}
664
+
660
665
if(hasEmptyShell){
661
666
if(dynamicValidation.hasSuspenseAboveBody){
662
667
// This route has opted into allowing fully dynamic rendering
@@ -698,7 +703,7 @@ export function throwIfDisallowedDynamic(
698
703
// to indicate your are ok with fully dynamic rendering.
699
704
if(dynamicValidation.hasDynamicViewport){
700
705
console.error(
701
-
`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`
706
+
`Route "${workStore.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`
702
707
)
703
708
thrownewStaticGenBailoutError()
704
709
}
@@ -708,7 +713,7 @@ export function throwIfDisallowedDynamic(
708
713
dynamicValidation.hasDynamicMetadata
709
714
){
710
715
console.error(
711
-
`Route "${route}" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata`
716
+
`Route "${workStore.route}" has a \`generateMetadata\` that depends on Request data (\`cookies()\`, etc...) or uncached external data (\`fetch(...)\`, etc...) when the rest of the route does not. See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata`
0 commit comments