Unverified Commit 4024a89e authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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 c325ecd6
...@@ -668,6 +668,7 @@ function createPatchedFetcher( ...@@ -668,6 +668,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
...@@ -695,6 +696,7 @@ function createPatchedFetcher( ...@@ -695,6 +696,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) {
......
...@@ -703,6 +703,8 @@ createNextDescribe( ...@@ -703,6 +703,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