Skip to content

Commit 2ef8ab9

Browse files
committed
fix: review updates
1 parent 5129d07 commit 2ef8ab9

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 9 additions & 16 deletions
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

Lines changed: 21 additions & 14 deletions
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

Lines changed: 9 additions & 10 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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()

0 commit comments

Comments
 (0)