Skip to content

Commit

Permalink
fix: review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Sep 30, 2024
1 parent 5129d07 commit 2ef8ab9
Show file tree
Hide file tree
Showing 34 changed files with 85 additions and 120 deletions.
2 changes: 2 additions & 0 deletions packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@ function warnAboutExperimentalEdge(apiRoute: string | null) {
) {
return
}

if (apiRouteWarnings.has(apiRoute)) {
return
}

Log.warn(
apiRoute
? `${apiRoute} provided runtime 'experimental-edge'. It can be updated to 'edge' instead.`
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/build/app-segments/app-segment-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const AppSegmentConfigSchema = z.object({
/**
* The runtime to use for the page.
*/
runtime: z.enum(['edge', 'nodejs', 'experimental-edge']).optional(),
runtime: z.enum(['edge', 'nodejs']).optional(),

/**
* The maximum duration for the page in seconds.
Expand Down Expand Up @@ -109,7 +109,7 @@ export type AppSegmentConfig = {
/**
* The runtime to use for the page.
*/
runtime?: 'edge' | 'nodejs' | 'experimental-edge'
runtime?: 'edge' | 'nodejs'

/**
* The maximum duration for the page in seconds.
Expand Down
25 changes: 9 additions & 16 deletions packages/next/src/build/app-segments/collect-app-segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ import { getLayoutOrPageModule } from '../../server/lib/app-dir-module'

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

/**
* Filters out segments that don't contribute to static generation.
*
* @param segments the segments to filter
* @returns the filtered segments
*/
function filterSegments(segments: AppSegment[]) {
return segments.filter((result) => {
return (
result.config || result.generateStaticParams || result.isDynamicSegment
)
})
}

/**
* Parses the app config and attaches it to the segment.
*/
Expand All @@ -60,6 +46,13 @@ function attach(segment: AppSegment, userland: unknown) {
) {
segment.generateStaticParams =
userland.generateStaticParams as GenerateStaticParams

// Validate that `generateStaticParams` makes sense in this context.
if (segment.config?.runtime === 'edge') {
throw new Error(
'Edge runtime is not supported with `generateStaticParams`.'
)
}
}
}

Expand Down Expand Up @@ -112,7 +105,7 @@ async function collectAppPageSegments(routeModule: AppPageRouteModule) {
current = parallelRoutes.children
}

return filterSegments(segments)
return segments
}

/**
Expand Down Expand Up @@ -154,7 +147,7 @@ function collectAppRouteSegments(
// Extract the segment config from the userland module.
attach(segment, routeModule.userland)

return filterSegments(segments)
return segments
}

/**
Expand Down
35 changes: 21 additions & 14 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
import { getRuntimeContext } from '../server/web/sandbox'
import { isClientReference } from '../lib/client-reference'
import { withStaticGenerationStore } from '../server/async-storage/with-static-generation-store'
import type { CacheHandler } from '../server/lib/incremental-cache'
import { IncrementalCache } from '../server/lib/incremental-cache'
import { nodeFs } from '../server/lib/node-fs-methods'
import * as ciEnvironment from '../server/ci-info'
Expand Down Expand Up @@ -1240,12 +1241,20 @@ export async function buildAppStaticPaths({
isAppPPRFallbacksEnabled: boolean | undefined
buildId: string
}): Promise<PartialStaticPathsResult> {
ComponentMod.patchFetch()
if (
segments.some((generate) => generate.config?.dynamicParams === true) &&
nextConfigOutput === 'export'
) {
throw new Error(
'"dynamicParams: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports'
)
}

let CacheHandler: any
ComponentMod.patchFetch()

let CurCacheHandler: typeof CacheHandler | undefined
if (cacheHandler) {
CacheHandler = interopDefault(
CurCacheHandler = interopDefault(
await import(formatDynamicImportPath(dir, cacheHandler)).then(
(mod) => mod.default || mod
)
Expand All @@ -1267,7 +1276,7 @@ export async function buildAppStaticPaths({
notFoundRoutes: [],
preview: null as any, // `preview` is special case read in next-dev-server
}),
CurCacheHandler: CacheHandler,
CurCacheHandler,
requestHeaders,
minimalMode: ciEnvironment.hasNextSupport,
})
Expand Down Expand Up @@ -1361,15 +1370,6 @@ export async function buildAppStaticPaths({
}
)

if (
segments.some((generate) => generate.config?.dynamicParams === true) &&
nextConfigOutput === 'export'
) {
throw new Error(
'"dynamicParams: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports'
)
}

for (const segment of segments) {
// Check to see if there are any missing params for segments that have
// dynamicParams set to false.
Expand Down Expand Up @@ -1588,7 +1588,14 @@ export async function isPageStatic({

isClientComponent = isClientReference(componentsResult.ComponentMod)

const segments = await collectSegments(componentsResult)
let segments
try {
segments = await collectSegments(componentsResult)
} catch (err) {
throw new Error(`Failed to collect configuration for ${page}`, {
cause: err,
})
}

appConfig = reduceAppConfig(await collectSegments(componentsResult))

Expand Down
19 changes: 9 additions & 10 deletions packages/next/src/server/dev/static-paths-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
checkIsRoutePPREnabled,
type ExperimentalPPRConfig,
} from '../lib/experimental/ppr'
import { InvariantError } from '../../shared/lib/invariant-error'

type RuntimeConfig = {
pprConfig: ExperimentalPPRConfig | undefined
Expand Down Expand Up @@ -80,22 +81,14 @@ export async function loadStaticPaths({
isAppPath,
})

if (!components.getStaticPaths && !isAppPath) {
// we shouldn't get to this point since the worker should
// only be called for SSG pages with getStaticPaths
throw new Error(
`Invariant: failed to load page with getStaticPaths for ${pathname}`
)
}

if (isAppPath) {
const segments = await collectSegments(components)

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

return await buildAppStaticPaths({
return buildAppStaticPaths({
dir,
page: pathname,
dynamicIO: config.dynamicIO,
Expand All @@ -113,9 +106,15 @@ export async function loadStaticPaths({
isAppPPRFallbacksEnabled,
buildId,
})
} else if (!components.getStaticPaths) {
// We shouldn't get to this point since the worker should only be called for
// SSG pages with getStaticPaths.
throw new InvariantError(
`Failed to load page with getStaticPaths for ${pathname}`
)
}

return await buildStaticPaths({
return buildStaticPaths({
page: pathname,
getStaticPaths: components.getStaticPaths,
configFileName: config.configFileName,
Expand Down
2 changes: 1 addition & 1 deletion test/.stats-app/app/app-edge-ssr/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default function page() {
return 'app-edge-ssr'
}

export const runtime = 'experimental-edge'
export const runtime = 'edge'
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-css/app/dashboard/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export default function DashboardPage(props) {
)
}

export const runtime = 'experimental-edge'
export const runtime = 'edge'
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-edge-root-layout/app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default function layout({ children }) {
)
}

export const runtime = 'experimental-edge'
export const runtime = 'edge'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextRequest } from 'next/server'
import { withRequestMeta } from '../../../../../helpers'

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

export async function POST(request: NextRequest) {
const body = await request.json()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NextRequest } from 'next/server'

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

export async function POST(request: NextRequest) {
const reader = request.body?.getReader()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextRequest } from 'next/server'
import { withRequestMeta } from '../../../../../helpers'

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

export async function POST(request: NextRequest) {
const body = await request.text()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { withRequestMeta } from '../../../../helpers'
import { NextRequest } from 'next/server'

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

export async function GET(request: NextRequest): Promise<Response> {
const { searchParams } = request.nextUrl
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-routes/app/edge/headers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { headers } from 'next/headers'
import { NextResponse } from 'next/server'
import { getRequestMeta } from '../../../helpers'

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

export async function GET() {
const meta = getRequestMeta(await headers())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@ export default async function Hello({ params }) {
return <h1 id="slug">{(await params).slug}</h1>
}

export function generateStaticParams() {
return [
{
slug: 'hello',
},
]
}

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

export default async function Page() {
const data = await fetch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const runtime = 'experimental-edge'
export const runtime = 'edge'

export default async function Page() {
const data = await fetch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cache, use } from 'react'

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

export default function Page() {
const getData = cache(() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const runtime = 'experimental-edge'
export const runtime = 'edge'

export default async function Page() {
const data = await fetch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchRetry } from '../../../lib/fetch-retry'

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

export default async function Page() {
const data = await fetchRetry(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cache, use } from 'react'

export const runtime = 'experimental-edge'
export const runtime = 'edge'
export const dynamic = 'force-static'

export default function Page() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default function HelloPage(props) {
)
}

export const runtime = 'experimental-edge'
export const runtime = 'edge'
export const preferredRegion = ['iad1', 'sfo1']
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/slow-page-no-loading/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export default function SlowPage(props) {
return <h1 id="slow-page-message">{data.message}</h1>
}

export const runtime = 'experimental-edge'
export const runtime = 'edge'
export const preferredRegion = 'global'
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/slow-page-with-loading/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export default function SlowPage(props) {
return <h1 id="slow-page-message">{data.message}</h1>
}

export const runtime = 'experimental-edge'
export const runtime = 'edge'
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/test-page/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export default function Page() {
return <p id="page">Page</p>
}

export const runtime = 'experimental-edge'
export const runtime = 'edge'
export const preferredRegion = 'home'
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { getSentinelValue } from '../../../../getSentinelValue'

export const runtime = 'edge'

export async function generateStaticParams() {
return [
{
dyn: '1',
},
]
}

export async function GET(
request: NextRequest,
props: { params: Promise<{ dyn: string }> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { getSentinelValue } from '../../../../getSentinelValue'

export const runtime = 'edge'

export async function generateStaticParams() {
return [
{
dyn: '1',
},
]
}

export async function GET(
request: NextRequest,
props: { params: Promise<{ dyn: string }> }
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/metadata/app/basic-edge/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Metadata } from 'next'
import Link from 'next/link'
import Client from './client'

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

export default function Page() {
return (
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/next-font/app/(preload)/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export default function HomePage() {
)
}

export const runtime = 'experimental-edge'
export const runtime = 'edge'
Loading

0 comments on commit 2ef8ab9

Please sign in to comment.