diff --git a/packages/next/src/server/app-render/app-render.tsx b/packages/next/src/server/app-render/app-render.tsx index 925b7f0785436..8f1ada65d8abc 100644 --- a/packages/next/src/server/app-render/app-render.tsx +++ b/packages/next/src/server/app-render/app-render.tsx @@ -3774,9 +3774,18 @@ async function prerenderToStream( type: 'prerender-legacy', phase: 'render', implicitTags: implicitTags, - revalidate: INFINITE_CACHE, - expire: INFINITE_CACHE, - stale: INFINITE_CACHE, + revalidate: + typeof prerenderStore?.revalidate !== 'undefined' + ? prerenderStore.revalidate + : INFINITE_CACHE, + expire: + typeof prerenderStore?.expire !== 'undefined' + ? prerenderStore.expire + : INFINITE_CACHE, + stale: + typeof prerenderStore?.stale !== 'undefined' + ? prerenderStore.stale + : INFINITE_CACHE, tags: [...(prerenderStore?.tags || implicitTags)], }) const errorRSCPayload = await workUnitAsyncStorage.run( diff --git a/test/e2e/app-dir/app-static/app-static.test.ts b/test/e2e/app-dir/app-static/app-static.test.ts index 56ccad8e0a5cf..04685bbd45b81 100644 --- a/test/e2e/app-dir/app-static/app-static.test.ts +++ b/test/e2e/app-dir/app-static/app-static.test.ts @@ -976,6 +976,10 @@ describe('app-dir static/dynamic handling', () => { "prerendered-not-found/first.rsc", "prerendered-not-found/second.html", "prerendered-not-found/second.rsc", + "prerendered-not-found/segment-revalidate.html", + "prerendered-not-found/segment-revalidate.rsc", + "prerendered-not-found/segment-revalidate/page.js", + "prerendered-not-found/segment-revalidate/page_client-reference-manifest.js", "react-fetch-deduping-edge/page.js", "react-fetch-deduping-edge/page_client-reference-manifest.js", "react-fetch-deduping-node/page.js", @@ -2008,6 +2012,30 @@ describe('app-dir static/dynamic handling', () => { "initialRevalidateSeconds": false, "srcRoute": "/prerendered-not-found/[slug]", }, + "/prerendered-not-found/segment-revalidate": { + "allowHeader": [ + "host", + "x-matched-path", + "x-prerender-revalidate", + "x-prerender-revalidate-if-generated", + "x-next-revalidated-tags", + "x-next-revalidate-tag-token", + ], + "dataRoute": "/prerendered-not-found/segment-revalidate.rsc", + "experimentalBypassFor": [ + { + "key": "Next-Action", + "type": "header", + }, + { + "key": "content-type", + "type": "header", + "value": "multipart/form-data;.*", + }, + ], + "initialRevalidateSeconds": 3, + "srcRoute": "/prerendered-not-found/segment-revalidate", + }, "/route-handler/no-store-force-static": { "allowHeader": [ "host", diff --git a/test/e2e/app-dir/app-static/app/prerendered-not-found/segment-revalidate/page.tsx b/test/e2e/app-dir/app-static/app/prerendered-not-found/segment-revalidate/page.tsx new file mode 100644 index 0000000000000..71ac497e935be --- /dev/null +++ b/test/e2e/app-dir/app-static/app/prerendered-not-found/segment-revalidate/page.tsx @@ -0,0 +1,23 @@ +import React from 'react' +import { notFound } from 'next/navigation' + +export const revalidate = 3 + +export default async function Page() { + await fetch('https://next-data-api.vercel.app/api/random', { + next: { + tags: ['explicit-tag'], + }, + }) + + if (process.env.NEXT_PHASE === 'phase-production-build') { + notFound() + } + + return ( + <> +

/prerendered-not-found/segment-revalidate

+

{Date.now()}

+ + ) +}