Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c31a2d

Browse files
ijjkztanner
authored andcommitted
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: #64462 Closes NEXT-3114
1 parent 2072327 commit 6c31a2d

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

packages/next/src/server/lib/patch-fetch.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ function createPatchedFetcher(
662662
const err = new DynamicServerError(dynamicUsageReason)
663663
staticGenerationStore.dynamicUsageErr = err
664664
staticGenerationStore.dynamicUsageDescription = dynamicUsageReason
665+
throw err
665666
}
666667

667668
const hasNextConfig = 'next' in init
@@ -689,6 +690,7 @@ function createPatchedFetcher(
689690
const err = new DynamicServerError(dynamicUsageReason)
690691
staticGenerationStore.dynamicUsageErr = err
691692
staticGenerationStore.dynamicUsageDescription = dynamicUsageReason
693+
throw err
692694
}
693695

694696
if (!staticGenerationStore.forceStatic || next.revalidate !== 0) {

test/e2e/app-dir/app-static/app-static.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ createNextDescribe(
671671
"force-dynamic-no-prerender/[id]/page_client-reference-manifest.js",
672672
"force-dynamic-prerender/[slug]/page.js",
673673
"force-dynamic-prerender/[slug]/page_client-reference-manifest.js",
674+
"force-no-store-bailout/page.js",
675+
"force-no-store-bailout/page_client-reference-manifest.js",
674676
"force-no-store/page.js",
675677
"force-no-store/page_client-reference-manifest.js",
676678
"force-static-fetch-no-store.html",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const fetchCache = 'force-no-store'
2+
3+
export default async function Page() {
4+
// this should not be invoked during build as
5+
// no-store should have it bail out
6+
await fetch('https://non-existent', {
7+
cache: 'no-store',
8+
})
9+
10+
return (
11+
<>
12+
<p id="page">/force-no-store-bailout</p>
13+
<p id="now">{Date.now()}</p>
14+
</>
15+
)
16+
}

0 commit comments

Comments
 (0)