Commit 6c31a2d4 authored by JJ Kasper's avatar JJ Kasper Committed by Zack Tanner

Fix DynamicServerError not being thrown in fetch (#64511)

This ensures we properly skip calling a fetch during build-time that has
`cache: 'no-store'` as it should only be called during runtime instead.

Fixes: https://github.com/vercel/next.js/issues/64462

Closes NEXT-3114
parent 2072327a
...@@ -662,6 +662,7 @@ function createPatchedFetcher( ...@@ -662,6 +662,7 @@ function createPatchedFetcher(
const err = new DynamicServerError(dynamicUsageReason) const err = new DynamicServerError(dynamicUsageReason)
staticGenerationStore.dynamicUsageErr = err staticGenerationStore.dynamicUsageErr = err
staticGenerationStore.dynamicUsageDescription = dynamicUsageReason staticGenerationStore.dynamicUsageDescription = dynamicUsageReason
throw err
} }
const hasNextConfig = 'next' in init const hasNextConfig = 'next' in init
...@@ -689,6 +690,7 @@ function createPatchedFetcher( ...@@ -689,6 +690,7 @@ function createPatchedFetcher(
const err = new DynamicServerError(dynamicUsageReason) const err = new DynamicServerError(dynamicUsageReason)
staticGenerationStore.dynamicUsageErr = err staticGenerationStore.dynamicUsageErr = err
staticGenerationStore.dynamicUsageDescription = dynamicUsageReason staticGenerationStore.dynamicUsageDescription = dynamicUsageReason
throw err
} }
if (!staticGenerationStore.forceStatic || next.revalidate !== 0) { if (!staticGenerationStore.forceStatic || next.revalidate !== 0) {
......
...@@ -671,6 +671,8 @@ createNextDescribe( ...@@ -671,6 +671,8 @@ createNextDescribe(
"force-dynamic-no-prerender/[id]/page_client-reference-manifest.js", "force-dynamic-no-prerender/[id]/page_client-reference-manifest.js",
"force-dynamic-prerender/[slug]/page.js", "force-dynamic-prerender/[slug]/page.js",
"force-dynamic-prerender/[slug]/page_client-reference-manifest.js", "force-dynamic-prerender/[slug]/page_client-reference-manifest.js",
"force-no-store-bailout/page.js",
"force-no-store-bailout/page_client-reference-manifest.js",
"force-no-store/page.js", "force-no-store/page.js",
"force-no-store/page_client-reference-manifest.js", "force-no-store/page_client-reference-manifest.js",
"force-static-fetch-no-store.html", "force-static-fetch-no-store.html",
......
export const fetchCache = 'force-no-store'
export default async function Page() {
// this should not be invoked during build as
// no-store should have it bail out
await fetch('https://non-existent', {
cache: 'no-store',
})
return (
<>
<p id="page">/force-no-store-bailout</p>
<p id="now">{Date.now()}</p>
</>
)
}
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