Unverified Commit ed12b552 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

Page Info Cleanup (#59430)

This updates the some of the logic around updating `PageInfo` entries in
the `pageInfos` map. This is a followup to #59420.

Closes NEXT-1838
parent d397b39d
...@@ -14,7 +14,7 @@ import { ...@@ -14,7 +14,7 @@ import {
import path from 'path' import path from 'path'
import fs from 'fs/promises' import fs from 'fs/promises'
import type { PageInfo } from './utils' import type { PageInfo } from './page-info'
import { loadBindings } from './swc' import { loadBindings } from './swc'
import { nonNullable } from '../lib/non-nullable' import { nonNullable } from '../lib/non-nullable'
import * as ciEnvironment from '../telemetry/ci-info' import * as ciEnvironment from '../telemetry/ci-info'
...@@ -79,7 +79,7 @@ export async function collectBuildTraces({ ...@@ -79,7 +79,7 @@ export async function collectBuildTraces({
staticPages: string[] staticPages: string[]
hasSsrAmpPages: boolean hasSsrAmpPages: boolean
outputFileTracingRoot: string outputFileTracingRoot: string
pageInfos: [string, PageInfo][] pageInfos: Map<string, PageInfo> | undefined
nextBuildSpan?: Span nextBuildSpan?: Span
config: NextConfigComplete config: NextConfigComplete
buildTraceContext?: BuildTraceContext buildTraceContext?: BuildTraceContext
...@@ -642,10 +642,8 @@ export async function collectBuildTraces({ ...@@ -642,10 +642,8 @@ export async function collectBuildTraces({
} }
// edge routes have no trace files // edge routes have no trace files
const [, pageInfo] = pageInfos.find((item) => item[0] === route) || [] const pageInfo = pageInfos?.get(route)
if (pageInfo?.runtime === 'edge') { if (pageInfo?.runtime === 'edge') return
return
}
const combinedIncludes = new Set<string>() const combinedIncludes = new Set<string>()
const combinedExcludes = new Set<string>() const combinedExcludes = new Set<string>()
......
...@@ -6,6 +6,7 @@ import type { MiddlewareManifest } from './webpack/plugins/middleware-plugin' ...@@ -6,6 +6,7 @@ import type { MiddlewareManifest } from './webpack/plugins/middleware-plugin'
import type { ActionManifest } from './webpack/plugins/flight-client-entry-plugin' import type { ActionManifest } from './webpack/plugins/flight-client-entry-plugin'
import type { ExportAppOptions, ExportAppWorker } from '../export/types' import type { ExportAppOptions, ExportAppWorker } from '../export/types'
import type { Revalidate } from '../server/lib/revalidate' import type { Revalidate } from '../server/lib/revalidate'
import type { PageInfo } from './page-info'
import '../lib/setup-exception-listeners' import '../lib/setup-exception-listeners'
...@@ -115,7 +116,7 @@ import { ...@@ -115,7 +116,7 @@ import {
isReservedPage, isReservedPage,
isAppBuiltinNotFoundPage, isAppBuiltinNotFoundPage,
} from './utils' } from './utils'
import type { PageInfo, AppConfig } from './utils' import type { AppConfig } from './utils'
import { writeBuildId } from './write-build-id' import { writeBuildId } from './write-build-id'
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import isError from '../lib/is-error' import isError from '../lib/is-error'
...@@ -160,6 +161,7 @@ import type { BuildTraceContext } from './webpack/plugins/next-trace-entrypoints ...@@ -160,6 +161,7 @@ import type { BuildTraceContext } from './webpack/plugins/next-trace-entrypoints
import { formatManifest } from './manifests/formatter/format-manifest' import { formatManifest } from './manifests/formatter/format-manifest'
import { getStartServerInfo, logStartInfo } from '../server/lib/app-info-log' import { getStartServerInfo, logStartInfo } from '../server/lib/app-info-log'
import type { NextEnabledDirectories } from '../server/base-server' import type { NextEnabledDirectories } from '../server/base-server'
import { RouteKind } from '../server/future/route-kind'
interface ExperimentalBypassForInfo { interface ExperimentalBypassForInfo {
experimentalBypassFor?: RouteHas[] experimentalBypassFor?: RouteHas[]
...@@ -1109,7 +1111,7 @@ export default async function build( ...@@ -1109,7 +1111,7 @@ export default async function build(
dir, dir,
config, config,
distDir, distDir,
pageInfos: [], pageInfos: undefined,
staticPages: [], staticPages: [],
hasSsrAmpPages: false, hasSsrAmpPages: false,
buildTraceContext, buildTraceContext,
...@@ -1923,7 +1925,7 @@ export default async function build( ...@@ -1923,7 +1925,7 @@ export default async function build(
dir, dir,
config, config,
distDir, distDir,
pageInfos: Object.entries(pageInfos), pageInfos,
staticPages: [...staticPages], staticPages: [...staticPages],
nextBuildSpan, nextBuildSpan,
hasSsrAmpPages, hasSsrAmpPages,
...@@ -2258,22 +2260,30 @@ export default async function build( ...@@ -2258,22 +2260,30 @@ export default async function build(
appConfig.revalidate === 0 || appConfig.revalidate === 0 ||
exportResult.byPath.get(page)?.revalidate === 0 exportResult.byPath.get(page)?.revalidate === 0
if (hasDynamicData && pageInfos.get(page)?.isStatic) { const pageInfo = pageInfos.get(page)
// if the page was marked as being static, but it contains dynamic data if (!pageInfo) {
// (ie, in the case of a static generation bailout), then it should be marked dynamic throw new Error(
pageInfos.set(page, { `Invariant: page info for ${page} is missing from registry`
...(pageInfos.get(page) as PageInfo), )
isStatic: false,
isSSG: false,
})
} }
const isRouteHandler = isAppRouteRoute(originalAppPath) if (hasDynamicData && pageInfo.isStatic) {
// If the page was marked as being static, but it contains dynamic
// data (ie, in the case of a static generation bailout), then it
// should be marked dynamic.
pageInfo.isStatic = false
pageInfo.isSSG = false
}
const isDynamic = isDynamicRoute(page)
const kind = isAppRouteRoute(originalAppPath)
? RouteKind.APP_ROUTE
: RouteKind.APP_PAGE
// When this is an app page and PPR is enabled, the route supports // When this is an app page and PPR is enabled, the route supports
// partial pre-rendering. // partial pre-rendering.
const experimentalPPR = const experimentalPPR =
!isRouteHandler && config.experimental.ppr === true kind === RouteKind.APP_PAGE && config.experimental.ppr === true
? true ? true
: undefined : undefined
...@@ -2299,34 +2309,27 @@ export default async function build( ...@@ -2299,34 +2309,27 @@ export default async function build(
hasPostponed, hasPostponed,
} = exportResult.byPath.get(route) ?? {} } = exportResult.byPath.get(route) ?? {}
pageInfos.set(route, { // If this route postponed and/or had an empty prelude, then
...(pageInfos.get(route) as PageInfo), // mark the page as having postponed and/or an empty prelude.
hasPostponed, pageInfo.hasPostponed ||= hasPostponed
hasEmptyPrelude, pageInfo.hasEmptyPrelude ||= hasEmptyPrelude
})
// update the page (eg /blog/[slug]) to also have the postpone metadata // Link the same pageInfo used for the `page` to this specific
pageInfos.set(page, { // `route` as they should all share the same characteristics.
...(pageInfos.get(page) as PageInfo), pageInfos.set(route, pageInfo)
hasPostponed,
hasEmptyPrelude,
})
if (revalidate !== 0) { if (revalidate !== 0) {
const normalizedRoute = normalizePagePath(route) let dataRoute: string | null = null
let prefetchDataRoute: string | undefined
let dataRoute: string | null
if (isRouteHandler) { // If this is for an app page, then we should associate a data
dataRoute = null // route (and prefetch if PPR is enabled) for it.
} else { if (kind === RouteKind.APP_PAGE) {
dataRoute = path.posix.join(`${normalizedRoute}${RSC_SUFFIX}`) const normalized = normalizePagePath(route)
} dataRoute = `${normalized}${RSC_SUFFIX}`
let prefetchDataRoute: string | null | undefined
if (experimentalPPR) { if (experimentalPPR) {
prefetchDataRoute = path.posix.join( prefetchDataRoute = `${normalized}${RSC_PREFETCH_SUFFIX}`
`${normalizedRoute}${RSC_PREFETCH_SUFFIX}` }
)
} }
const routeMeta: Partial<SsgRoute> = {} const routeMeta: Partial<SsgRoute> = {}
...@@ -2373,34 +2376,30 @@ export default async function build( ...@@ -2373,34 +2376,30 @@ export default async function build(
hasDynamicData = true hasDynamicData = true
// we might have determined during prerendering that this page // we might have determined during prerendering that this page
// used dynamic data // used dynamic data
pageInfos.set(route, { pageInfo.isStatic = false
...(pageInfos.get(route) as PageInfo), pageInfo.isSSG = false
isSSG: false,
isStatic: false,
})
} }
}) })
if (!hasDynamicData && isDynamicRoute(originalAppPath)) { if (!hasDynamicData && isDynamic) {
const normalizedRoute = normalizePagePath(page) let dataRoute: string | null = null
const dataRoute = path.posix.join( let prefetchDataRoute: string | undefined
`${normalizedRoute}${RSC_SUFFIX}`
)
let prefetchDataRoute: string | null | undefined // If this is for an app page, then we should associate a data
// route (and prefetch if PPR is enabled) for it.
if (kind === RouteKind.APP_PAGE) {
const normalized = normalizePagePath(page)
dataRoute = `${normalized}${RSC_SUFFIX}`
if (experimentalPPR) { if (experimentalPPR) {
prefetchDataRoute = path.posix.join( prefetchDataRoute = `${normalized}${RSC_PREFETCH_SUFFIX}`
`${normalizedRoute}${RSC_PREFETCH_SUFFIX}` }
)
} }
pageInfos.set(page, { pageInfo.isDynamicAppRoute = true
...(pageInfos.get(page) as PageInfo),
isDynamicAppRoute: true, // If PPR is turned on and the route contains a dynamic segment,
// if PPR is turned on and the route contains a dynamic segment,
// we assume it'll be partially prerendered // we assume it'll be partially prerendered
hasPostponed: experimentalPPR, pageInfo.hasPostponed = experimentalPPR
})
// TODO: create a separate manifest to allow enforcing // TODO: create a separate manifest to allow enforcing
// dynamicParams for non-static paths? // dynamicParams for non-static paths?
...@@ -2410,25 +2409,23 @@ export default async function build( ...@@ -2410,25 +2409,23 @@ export default async function build(
routeRegex: normalizeRouteRegex( routeRegex: normalizeRouteRegex(
getNamedRouteRegex(page, false).re.source getNamedRouteRegex(page, false).re.source
), ),
dataRoute,
// if dynamicParams are enabled treat as fallback: // if dynamicParams are enabled treat as fallback:
// 'blocking' if not it's fallback: false // 'blocking' if not it's fallback: false
fallback: appDynamicParamPaths.has(originalAppPath) fallback: appDynamicParamPaths.has(originalAppPath)
? null ? null
: false, : false,
dataRouteRegex: isRouteHandler dataRoute,
? null dataRouteRegex: dataRoute
: normalizeRouteRegex( ? normalizeRouteRegex(
getNamedRouteRegex( getNamedRouteRegex(
dataRoute.replace(/\.rsc$/, ''), dataRoute.replace(/\.rsc$/, ''),
false false
).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.rsc$') ).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.rsc$')
), )
: null,
prefetchDataRoute, prefetchDataRoute,
prefetchDataRouteRegex: prefetchDataRouteRegex: prefetchDataRoute
isRouteHandler || !prefetchDataRoute ? normalizeRouteRegex(
? undefined
: normalizeRouteRegex(
getNamedRouteRegex( getNamedRouteRegex(
prefetchDataRoute.replace(/\.prefetch\.rsc$/, ''), prefetchDataRoute.replace(/\.prefetch\.rsc$/, ''),
false false
...@@ -2436,7 +2433,8 @@ export default async function build( ...@@ -2436,7 +2433,8 @@ export default async function build(
/\(\?:\\\/\)\?\$$/, /\(\?:\\\/\)\?\$$/,
'\\.prefetch\\.rsc$' '\\.prefetch\\.rsc$'
) )
), )
: undefined,
} }
} }
} }
......
import type { ServerRuntime } from '../../types'
export interface PageInfo {
isHybridAmp?: boolean
size: number
totalSize: number
isStatic: boolean
isSSG: boolean
isPPR: boolean
ssgPageRoutes: string[] | null
initialRevalidateSeconds: number | false
pageDuration: number | undefined
ssgPageDurations: number[] | undefined
runtime: ServerRuntime
hasEmptyPrelude?: boolean
hasPostponed?: boolean
isDynamicAppRoute?: boolean
}
...@@ -23,6 +23,7 @@ import type { AppPageModule } from '../server/future/route-modules/app-page/modu ...@@ -23,6 +23,7 @@ import type { AppPageModule } from '../server/future/route-modules/app-page/modu
import type { RouteModule } from '../server/future/route-modules/route-module' import type { RouteModule } from '../server/future/route-modules/route-module'
import type { LoaderTree } from '../server/lib/app-dir-module' import type { LoaderTree } from '../server/lib/app-dir-module'
import type { NextComponentType } from '../shared/lib/utils' import type { NextComponentType } from '../shared/lib/utils'
import type { PageInfo } from './page-info'
import '../server/require-hook' import '../server/require-hook'
import '../server/node-polyfill-crypto' import '../server/node-polyfill-crypto'
...@@ -326,23 +327,6 @@ const filterAndSortList = ( ...@@ -326,23 +327,6 @@ const filterAndSortList = (
return pages.sort((a, b) => a.localeCompare(b)) return pages.sort((a, b) => a.localeCompare(b))
} }
export interface PageInfo {
isHybridAmp?: boolean
size: number
totalSize: number
isStatic: boolean
isSSG: boolean
isPPR: boolean
ssgPageRoutes: string[] | null
initialRevalidateSeconds: number | false
pageDuration: number | undefined
ssgPageDurations: number[] | undefined
runtime: ServerRuntime
hasEmptyPrelude?: boolean
hasPostponed?: boolean
isDynamicAppRoute?: boolean
}
export async function printTreeView( export async function printTreeView(
lists: { lists: {
pages: ReadonlyArray<string> pages: ReadonlyArray<string>
...@@ -647,10 +631,15 @@ export async function printTreeView( ...@@ -647,10 +631,15 @@ export async function printTreeView(
messages.push(['', '', '']) messages.push(['', '', ''])
} }
// We should update the `isStatic` part of the pageInfo for the /404 page.
// When we're using experimental compile, this won't be available.
const pageInfo = pageInfos.get('/404') || pageInfos.get('/_error')
if (pageInfo) {
pageInfos.set('/404', { pageInfos.set('/404', {
...(pageInfos.get('/404') || pageInfos.get('/_error'))!, ...pageInfo,
isStatic: useStaticPages404, isStatic: useStaticPages404,
}) })
}
// If there's no app /_notFound page present, then the 404 is still using the pages/404 // If there's no app /_notFound page present, then the 404 is still using the pages/404
if (!lists.pages.includes('/404') && !lists.app?.includes('/_not-found')) { if (!lists.pages.includes('/404') && !lists.app?.includes('/_not-found')) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment