diff --git a/packages/next/src/build/analysis/get-page-static-info.ts b/packages/next/src/build/analysis/get-page-static-info.ts index ec08c72f4a6c6..9f1d890a050c0 100644 --- a/packages/next/src/build/analysis/get-page-static-info.ts +++ b/packages/next/src/build/analysis/get-page-static-info.ts @@ -21,7 +21,7 @@ import type { RSCMeta } from '../webpack/loaders/get-module-build-info' // TODO: migrate preferredRegion here // Don't forget to update the next-types-plugin file as well -const AUTHORIZED_EXTRA_PROPS = ['maxDuration'] +const AUTHORIZED_EXTRA_ROUTER_PROPS = ['maxDuration'] export interface MiddlewareConfig { matchers?: MiddlewareMatcher[] @@ -509,13 +509,11 @@ export async function getPageStaticInfo(params: { // `export config` doesn't exist, or other unknown error throw by swc, silence them } - let extraConfig: Record | undefined - - if (extraProperties) { - extraConfig = {} + const extraConfig: Record = {} + if (extraProperties && pageType === 'app') { for (const prop of extraProperties) { - if (!AUTHORIZED_EXTRA_PROPS.includes(prop)) continue + if (!AUTHORIZED_EXTRA_ROUTER_PROPS.includes(prop)) continue try { extraConfig[prop] = extractExportedConstValue(swcAST, prop) } catch (e) { @@ -524,6 +522,11 @@ export async function getPageStaticInfo(params: { } } } + } else if (pageType === 'pages') { + for (const key in config) { + if (!AUTHORIZED_EXTRA_ROUTER_PROPS.includes(key)) continue + extraConfig[key] = config[key] + } } if (pageType === 'app') { diff --git a/test/e2e/app-dir/with-exported-function-config/pages/api/page-route.ts b/test/e2e/app-dir/with-exported-function-config/pages/api/page-route.ts index 354559f3e6201..26b4b1ddf8f68 100644 --- a/test/e2e/app-dir/with-exported-function-config/pages/api/page-route.ts +++ b/test/e2e/app-dir/with-exported-function-config/pages/api/page-route.ts @@ -7,4 +7,4 @@ export default function handler( return res.status(200).json({ hello: 'world' }) } -export const maxDuration = 1 +export const config = { maxDuration: 1 } diff --git a/test/e2e/app-dir/with-exported-function-config/pages/page-ssr.tsx b/test/e2e/app-dir/with-exported-function-config/pages/page-ssr.tsx index fd898a4d2bdbf..f406d9e5b60f9 100644 --- a/test/e2e/app-dir/with-exported-function-config/pages/page-ssr.tsx +++ b/test/e2e/app-dir/with-exported-function-config/pages/page-ssr.tsx @@ -2,7 +2,9 @@ export default function Page({ data }) { ;

hello {data}

} -export const maxDuration = 3 +export const config = { + maxDuration: 3, +} export async function getServerSideProps() { return { props: { data: 'world' } } diff --git a/test/e2e/app-dir/with-exported-function-config/pages/page.tsx b/test/e2e/app-dir/with-exported-function-config/pages/page.tsx index 01f69e141dfc6..e6534696ca015 100644 --- a/test/e2e/app-dir/with-exported-function-config/pages/page.tsx +++ b/test/e2e/app-dir/with-exported-function-config/pages/page.tsx @@ -2,4 +2,6 @@ export default function Page() { ;

hello world

} -export const maxDuration = 2 +export const config = { + maxDuration: 2, +}