Skip to content

Commit

Permalink
[functions-config-manifest] use correct extra config for pages router (
Browse files Browse the repository at this point in the history
…#54786)

When using page routes we need to pass the contents of the `export const config` to the `extraConfig` populating the functions config manifest rather then relying on named exports like in app router.
  • Loading branch information
ecklf authored Sep 5, 2023
1 parent 7a256e6 commit ffd504c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
15 changes: 9 additions & 6 deletions packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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<string, any> | undefined

if (extraProperties) {
extraConfig = {}
const extraConfig: Record<string, any> = {}

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) {
Expand All @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default function handler(
return res.status(200).json({ hello: 'world' })
}

export const maxDuration = 1
export const config = { maxDuration: 1 }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export default function Page({ data }) {
;<p>hello {data}</p>
}

export const maxDuration = 3
export const config = {
maxDuration: 3,
}

export async function getServerSideProps() {
return { props: { data: 'world' } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export default function Page() {
;<p>hello world</p>
}

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

0 comments on commit ffd504c

Please sign in to comment.