Skip to content

Commit 93210ff

Browse files
committed
fix: review updates
1 parent 33372ee commit 93210ff

File tree

34 files changed

+85
-120
lines changed

34 files changed

+85
-120
lines changed

packages/next/src/build/analysis/get-page-static-info.ts

+2
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,11 @@ function warnAboutExperimentalEdge(apiRoute: string | null) {
437437
) {
438438
return
439439
}
440+
440441
if (apiRouteWarnings.has(apiRoute)) {
441442
return
442443
}
444+
443445
Log.warn(
444446
apiRoute
445447
? `${apiRoute} provided runtime 'experimental-edge'. It can be updated to 'edge' instead.`

packages/next/src/build/app-segments/app-segment-config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const AppSegmentConfigSchema = z.object({
5555
/**
5656
* The runtime to use for the page.
5757
*/
58-
runtime: z.enum(['edge', 'nodejs', 'experimental-edge']).optional(),
58+
runtime: z.enum(['edge', 'nodejs']).optional(),
5959

6060
/**
6161
* The maximum duration for the page in seconds.
@@ -109,7 +109,7 @@ export type AppSegmentConfig = {
109109
/**
110110
* The runtime to use for the page.
111111
*/
112-
runtime?: 'edge' | 'nodejs' | 'experimental-edge'
112+
runtime?: 'edge' | 'nodejs'
113113

114114
/**
115115
* The maximum duration for the page in seconds.

packages/next/src/build/app-segments/collect-app-segments.ts

+9-16
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ import { getLayoutOrPageModule } from '../../server/lib/app-dir-module'
2424

2525
type GenerateStaticParams = (options: { params?: Params }) => Promise<Params[]>
2626

27-
/**
28-
* Filters out segments that don't contribute to static generation.
29-
*
30-
* @param segments the segments to filter
31-
* @returns the filtered segments
32-
*/
33-
function filterSegments(segments: AppSegment[]) {
34-
return segments.filter((result) => {
35-
return (
36-
result.config || result.generateStaticParams || result.isDynamicSegment
37-
)
38-
})
39-
}
40-
4127
/**
4228
* Parses the app config and attaches it to the segment.
4329
*/
@@ -60,6 +46,13 @@ function attach(segment: AppSegment, userland: unknown) {
6046
) {
6147
segment.generateStaticParams =
6248
userland.generateStaticParams as GenerateStaticParams
49+
50+
// Validate that `generateStaticParams` makes sense in this context.
51+
if (segment.config?.runtime === 'edge') {
52+
throw new Error(
53+
'Edge runtime is not supported with `generateStaticParams`.'
54+
)
55+
}
6356
}
6457
}
6558

@@ -112,7 +105,7 @@ async function collectAppPageSegments(routeModule: AppPageRouteModule) {
112105
current = parallelRoutes.children
113106
}
114107

115-
return filterSegments(segments)
108+
return segments
116109
}
117110

118111
/**
@@ -154,7 +147,7 @@ function collectAppRouteSegments(
154147
// Extract the segment config from the userland module.
155148
attach(segment, routeModule.userland)
156149

157-
return filterSegments(segments)
150+
return segments
158151
}
159152

160153
/**

packages/next/src/build/utils.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
7676
import { getRuntimeContext } from '../server/web/sandbox'
7777
import { isClientReference } from '../lib/client-reference'
7878
import { withStaticGenerationStore } from '../server/async-storage/with-static-generation-store'
79+
import type { CacheHandler } from '../server/lib/incremental-cache'
7980
import { IncrementalCache } from '../server/lib/incremental-cache'
8081
import { nodeFs } from '../server/lib/node-fs-methods'
8182
import * as ciEnvironment from '../server/ci-info'
@@ -1240,12 +1241,20 @@ export async function buildAppStaticPaths({
12401241
isAppPPRFallbacksEnabled: boolean | undefined
12411242
buildId: string
12421243
}): Promise<PartialStaticPathsResult> {
1243-
ComponentMod.patchFetch()
1244+
if (
1245+
segments.some((generate) => generate.config?.dynamicParams === true) &&
1246+
nextConfigOutput === 'export'
1247+
) {
1248+
throw new Error(
1249+
'"dynamicParams: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports'
1250+
)
1251+
}
12441252

1245-
let CacheHandler: any
1253+
ComponentMod.patchFetch()
12461254

1255+
let CurCacheHandler: typeof CacheHandler | undefined
12471256
if (cacheHandler) {
1248-
CacheHandler = interopDefault(
1257+
CurCacheHandler = interopDefault(
12491258
await import(formatDynamicImportPath(dir, cacheHandler)).then(
12501259
(mod) => mod.default || mod
12511260
)
@@ -1267,7 +1276,7 @@ export async function buildAppStaticPaths({
12671276
notFoundRoutes: [],
12681277
preview: null as any, // `preview` is special case read in next-dev-server
12691278
}),
1270-
CurCacheHandler: CacheHandler,
1279+
CurCacheHandler,
12711280
requestHeaders,
12721281
minimalMode: ciEnvironment.hasNextSupport,
12731282
})
@@ -1361,15 +1370,6 @@ export async function buildAppStaticPaths({
13611370
}
13621371
)
13631372

1364-
if (
1365-
segments.some((generate) => generate.config?.dynamicParams === true) &&
1366-
nextConfigOutput === 'export'
1367-
) {
1368-
throw new Error(
1369-
'"dynamicParams: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports'
1370-
)
1371-
}
1372-
13731373
for (const segment of segments) {
13741374
// Check to see if there are any missing params for segments that have
13751375
// dynamicParams set to false.
@@ -1588,7 +1588,14 @@ export async function isPageStatic({
15881588

15891589
isClientComponent = isClientReference(componentsResult.ComponentMod)
15901590

1591-
const segments = await collectSegments(componentsResult)
1591+
let segments
1592+
try {
1593+
segments = await collectSegments(componentsResult)
1594+
} catch (err) {
1595+
throw new Error(`Failed to collect configuration for ${page}`, {
1596+
cause: err,
1597+
})
1598+
}
15921599

15931600
appConfig = reduceAppConfig(await collectSegments(componentsResult))
15941601

packages/next/src/server/dev/static-paths-worker.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
checkIsRoutePPREnabled,
1919
type ExperimentalPPRConfig,
2020
} from '../lib/experimental/ppr'
21+
import { InvariantError } from '../../shared/lib/invariant-error'
2122

2223
type RuntimeConfig = {
2324
pprConfig: ExperimentalPPRConfig | undefined
@@ -80,22 +81,14 @@ export async function loadStaticPaths({
8081
isAppPath,
8182
})
8283

83-
if (!components.getStaticPaths && !isAppPath) {
84-
// we shouldn't get to this point since the worker should
85-
// only be called for SSG pages with getStaticPaths
86-
throw new Error(
87-
`Invariant: failed to load page with getStaticPaths for ${pathname}`
88-
)
89-
}
90-
9184
if (isAppPath) {
9285
const segments = await collectSegments(components)
9386

9487
const isRoutePPREnabled =
9588
isAppPageRouteModule(components.routeModule) &&
9689
checkIsRoutePPREnabled(config.pprConfig, reduceAppConfig(segments))
9790

98-
return await buildAppStaticPaths({
91+
return buildAppStaticPaths({
9992
dir,
10093
page: pathname,
10194
dynamicIO: config.dynamicIO,
@@ -113,9 +106,15 @@ export async function loadStaticPaths({
113106
isAppPPRFallbacksEnabled,
114107
buildId,
115108
})
109+
} else if (!components.getStaticPaths) {
110+
// We shouldn't get to this point since the worker should only be called for
111+
// SSG pages with getStaticPaths.
112+
throw new InvariantError(
113+
`Failed to load page with getStaticPaths for ${pathname}`
114+
)
116115
}
117116

118-
return await buildStaticPaths({
117+
return buildStaticPaths({
119118
page: pathname,
120119
getStaticPaths: components.getStaticPaths,
121120
configFileName: config.configFileName,

test/.stats-app/app/app-edge-ssr/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export default function page() {
22
return 'app-edge-ssr'
33
}
44

5-
export const runtime = 'experimental-edge'
5+
export const runtime = 'edge'

test/e2e/app-dir/app-css/app/dashboard/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export default function DashboardPage(props) {
1313
)
1414
}
1515

16-
export const runtime = 'experimental-edge'
16+
export const runtime = 'edge'

test/e2e/app-dir/app-edge-root-layout/app/layout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export default function layout({ children }) {
66
)
77
}
88

9-
export const runtime = 'experimental-edge'
9+
export const runtime = 'edge'

test/e2e/app-dir/app-routes/app/edge/advanced/body/json/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextRequest } from 'next/server'
22
import { withRequestMeta } from '../../../../../helpers'
33

4-
export const runtime = 'experimental-edge'
4+
export const runtime = 'edge'
55

66
export async function POST(request: NextRequest) {
77
const body = await request.json()

test/e2e/app-dir/app-routes/app/edge/advanced/body/streaming/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { NextRequest } from 'next/server'
22

3-
export const runtime = 'experimental-edge'
3+
export const runtime = 'edge'
44

55
export async function POST(request: NextRequest) {
66
const reader = request.body?.getReader()

test/e2e/app-dir/app-routes/app/edge/advanced/body/text/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextRequest } from 'next/server'
22
import { withRequestMeta } from '../../../../../helpers'
33

4-
export const runtime = 'experimental-edge'
4+
export const runtime = 'edge'
55

66
export async function POST(request: NextRequest) {
77
const body = await request.text()

test/e2e/app-dir/app-routes/app/edge/advanced/query/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { withRequestMeta } from '../../../../helpers'
22
import { NextRequest } from 'next/server'
33

4-
export const runtime = 'experimental-edge'
4+
export const runtime = 'edge'
55

66
export async function GET(request: NextRequest): Promise<Response> {
77
const { searchParams } = request.nextUrl

test/e2e/app-dir/app-routes/app/edge/headers/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { headers } from 'next/headers'
22
import { NextResponse } from 'next/server'
33
import { getRequestMeta } from '../../../helpers'
44

5-
export const runtime = 'experimental-edge'
5+
export const runtime = 'edge'
66

77
export async function GET() {
88
const meta = getRequestMeta(await headers())

test/e2e/app-dir/app-static/app/dynamic-param-edge/[slug]/page.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,4 @@ export default async function Hello({ params }) {
22
return <h1 id="slug">{(await params).slug}</h1>
33
}
44

5-
export function generateStaticParams() {
6-
return [
7-
{
8-
slug: 'hello',
9-
},
10-
]
11-
}
12-
135
export const runtime = 'edge'

test/e2e/app-dir/app-static/app/variable-revalidate-edge/body/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const runtime = 'experimental-edge'
1+
export const runtime = 'edge'
22

33
export default async function Page() {
44
const data = await fetch(

test/e2e/app-dir/app-static/app/variable-revalidate-edge/encoding/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const runtime = 'experimental-edge'
1+
export const runtime = 'edge'
22

33
export default async function Page() {
44
const data = await fetch(

test/e2e/app-dir/app-static/app/variable-revalidate-edge/no-store/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cache, use } from 'react'
22

3-
export const runtime = 'experimental-edge'
3+
export const runtime = 'edge'
44

55
export default function Page() {
66
const getData = cache(() =>

test/e2e/app-dir/app-static/app/variable-revalidate-edge/post-method-request/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const runtime = 'experimental-edge'
1+
export const runtime = 'edge'
22

33
export default async function Page() {
44
const data = await fetch(

test/e2e/app-dir/app-static/app/variable-revalidate-edge/post-method/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fetchRetry } from '../../../lib/fetch-retry'
22

3-
export const runtime = 'experimental-edge'
3+
export const runtime = 'edge'
44

55
export default async function Page() {
66
const data = await fetchRetry(

test/e2e/app-dir/app-static/app/variable-revalidate-edge/revalidate-3/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cache, use } from 'react'
22

3-
export const runtime = 'experimental-edge'
3+
export const runtime = 'edge'
44
export const dynamic = 'force-static'
55

66
export default function Page() {

test/e2e/app-dir/app/app/(rootonly)/dashboard/hello/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export default function HelloPage(props) {
66
)
77
}
88

9-
export const runtime = 'experimental-edge'
9+
export const runtime = 'edge'
1010
export const preferredRegion = ['iad1', 'sfo1']

test/e2e/app-dir/app/app/slow-page-no-loading/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export default function SlowPage(props) {
1313
return <h1 id="slow-page-message">{data.message}</h1>
1414
}
1515

16-
export const runtime = 'experimental-edge'
16+
export const runtime = 'edge'
1717
export const preferredRegion = 'global'

test/e2e/app-dir/app/app/slow-page-with-loading/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export default function SlowPage(props) {
1313
return <h1 id="slow-page-message">{data.message}</h1>
1414
}
1515

16-
export const runtime = 'experimental-edge'
16+
export const runtime = 'edge'

test/e2e/app-dir/app/app/test-page/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export default function Page() {
22
return <p id="page">Page</p>
33
}
44

5-
export const runtime = 'experimental-edge'
5+
export const runtime = 'edge'
66
export const preferredRegion = 'home'

test/e2e/app-dir/dynamic-io/app/routes/-edge/[dyn]/async/route.ts

-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import { getSentinelValue } from '../../../../getSentinelValue'
44

55
export const runtime = 'edge'
66

7-
export async function generateStaticParams() {
8-
return [
9-
{
10-
dyn: '1',
11-
},
12-
]
13-
}
14-
157
export async function GET(
168
request: NextRequest,
179
props: { params: Promise<{ dyn: string }> }

test/e2e/app-dir/dynamic-io/app/routes/-edge/[dyn]/sync/route.ts

-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import { getSentinelValue } from '../../../../getSentinelValue'
44

55
export const runtime = 'edge'
66

7-
export async function generateStaticParams() {
8-
return [
9-
{
10-
dyn: '1',
11-
},
12-
]
13-
}
14-
157
export async function GET(
168
request: NextRequest,
179
props: { params: Promise<{ dyn: string }> }

test/e2e/app-dir/metadata/app/basic-edge/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Metadata } from 'next'
22
import Link from 'next/link'
33
import Client from './client'
44

5-
export const runtime = 'experimental-edge'
5+
export const runtime = 'edge'
66

77
export default function Page() {
88
return (

test/e2e/app-dir/next-font/app/(preload)/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export default function HomePage() {
1313
)
1414
}
1515

16-
export const runtime = 'experimental-edge'
16+
export const runtime = 'edge'

0 commit comments

Comments
 (0)