diff --git a/packages/next/client/components/static-generation-bailout.ts b/packages/next/client/components/static-generation-bailout.ts index 9d30421e87c1..20e585f4ac71 100644 --- a/packages/next/client/components/static-generation-bailout.ts +++ b/packages/next/client/components/static-generation-bailout.ts @@ -10,7 +10,7 @@ export function staticGenerationBailout(reason: string) { if (staticGenerationStore?.isStaticGeneration) { // TODO: honor the dynamic: 'force-static' if (staticGenerationStore) { - staticGenerationStore.revalidate = 0 + staticGenerationStore.fetchRevalidate = 0 } throw new DynamicServerError(reason) } diff --git a/packages/next/server/app-render.tsx b/packages/next/server/app-render.tsx index 63cc14cf86a5..67789f3d1bfe 100644 --- a/packages/next/server/app-render.tsx +++ b/packages/next/server/app-render.tsx @@ -238,13 +238,13 @@ function patchFetch(ComponentMod: any) { ) { staticGenerationStore.fetchRevalidate = next.revalidate - // TODO: ensure this error isn't logged to the user - // seems it's slipping through currently - throw new DynamicServerError( - `revalidate: ${next.revalidate} fetch ${input}${ - pathname ? ` ${pathname}` : '' - }` - ) + if (next.revalidate === 0) { + throw new DynamicServerError( + `revalidate: ${next.revalidate} fetch ${input}${ + pathname ? ` ${pathname}` : '' + }` + ) + } } if (hasNextConfig) delete init.next } @@ -735,7 +735,9 @@ export async function renderToHTMLOrFlight( supportsDynamicHTML, } = renderOpts - patchFetch(ComponentMod) + if (process.env.NODE_ENV === 'production') { + patchFetch(ComponentMod) + } const generateStaticHTML = supportsDynamicHTML !== true const staticGenerationAsyncStorage = ComponentMod.staticGenerationAsyncStorage @@ -1619,9 +1621,9 @@ export async function renderToHTMLOrFlight( ;(renderOpts as any).pageData = filteredFlightData ;(renderOpts as any).revalidate = - typeof staticGenerationStore?.revalidate === 'undefined' + typeof staticGenerationStore?.fetchRevalidate === 'undefined' ? defaultRevalidate - : staticGenerationStore?.revalidate + : staticGenerationStore?.fetchRevalidate return new RenderResult(htmlResult) } diff --git a/test/e2e/app-dir/app-static/app/blog/[author]/page.js b/test/e2e/app-dir/app-static/app/blog/[author]/page.js index 18ff1b30cde8..fa5e3e0b23d6 100644 --- a/test/e2e/app-dir/app-static/app/blog/[author]/page.js +++ b/test/e2e/app-dir/app-static/app/blog/[author]/page.js @@ -2,7 +2,10 @@ import Link from 'next/link' export const dynamicParams = false -export default function Page({ params }) { +export default async function Page({ params }) { + await fetch('https://example.vercel.sh', { + next: { revalidate: 10 }, + }) return ( <>

/blog/[author]