Unverified Commit b5da7b7f authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

[build info]: distinguish between PPR and fully static routes in gSP (#92518)

With `cacheComponents`, it's possible with `generateStaticParams` to produce a fully static route, while other sub-routes might still be partially prerendered. This updates the build info to distinguish between the two. 

Before:
```
├ ◐ /params/semantics/[lowcard]/[highcard]/layout-has/server
│ ├ /params/semantics/[lowcard]/[highcard]/layout-has/server
│ ├ /params/semantics/one/[highcard]/layout-has/server
│ └ /params/semantics/one/build/layout-has/server
```

After:
```
├ ◐ /params/semantics/[lowcard]/[highcard]/layout-has/server
│ ├ ◐ /params/semantics/[lowcard]/[highcard]/layout-has/server
│ ├ ◐ /params/semantics/one/[highcard]/layout-has/server
│ └ ○ /params/semantics/one/build/layout-has/server
```
parent fd340450
...@@ -3213,6 +3213,7 @@ export default async function build( ...@@ -3213,6 +3213,7 @@ export default async function build(
for (const route of staticPrerenderedRoutes) { for (const route of staticPrerenderedRoutes) {
if (isDynamicRoute(page) && route.pathname === page) continue if (isDynamicRoute(page) && route.pathname === page) continue
const pageInfo = pageInfos.get(page) as PageInfo
const { const {
metadata = {}, metadata = {},
hasEmptyStaticShell, hasEmptyStaticShell,
...@@ -3225,8 +3226,18 @@ export default async function build( ...@@ -3225,8 +3226,18 @@ export default async function build(
appConfig.revalidate appConfig.revalidate
) )
// Generated concrete paths (for example `/blog/post-1`) inherit
// the route-level classification from the dynamic page
// (`/blog/[slug]`), but they also need their own export-time
// metadata so the tree view can show whether that specific path
// ended up fully static or partially prerendered.
pageInfos.set(route.pathname, { pageInfos.set(route.pathname, {
...pageInfo,
...(pageInfos.get(route.pathname) as PageInfo), ...(pageInfos.get(route.pathname) as PageInfo),
ssgPageRoutes: null,
ssgPageDurations: undefined,
pageDuration: undefined,
isDynamicAppRoute: false,
hasPostponed, hasPostponed,
hasEmptyStaticShell, hasEmptyStaticShell,
initialCacheControl: cacheControl, initialCacheControl: cacheControl,
...@@ -3286,7 +3297,7 @@ export default async function build( ...@@ -3286,7 +3297,7 @@ export default async function build(
hasRevalidateZero = true hasRevalidateZero = true
if (ssgPageRoutesSet.has(route.pathname)) { if (ssgPageRoutesSet.has(route.pathname)) {
const pageInfo = pageInfos.get(page) as PageInfo const currentPageInfo = pageInfos.get(page) as PageInfo
// Remove the route from the SSG page routes if it bailed out // Remove the route from the SSG page routes if it bailed out
// during prerendering. // during prerendering.
ssgPageRoutesSet.delete(route.pathname) ssgPageRoutesSet.delete(route.pathname)
...@@ -3299,10 +3310,13 @@ export default async function build( ...@@ -3299,10 +3310,13 @@ export default async function build(
} }
pageInfos.set(page, { pageInfos.set(page, {
...pageInfo, ...currentPageInfo,
ssgPageRoutes: Array.from(ssgPageRoutesSet), ssgPageRoutes: Array.from(ssgPageRoutesSet),
// If there are no SSG page routes left, then the page is not SSG. // If there are no SSG page routes left, then the page is not SSG.
isSSG: ssgPageRoutesSet.size === 0 ? false : pageInfo.isSSG, isSSG:
ssgPageRoutesSet.size === 0
? false
: currentPageInfo.isSSG,
}) })
} else { } else {
// we might have determined during prerendering that this page // we might have determined during prerendering that this page
...@@ -3336,6 +3350,7 @@ export default async function build( ...@@ -3336,6 +3350,7 @@ export default async function build(
for (const route of dynamicPrerenderedRoutes) { for (const route of dynamicPrerenderedRoutes) {
const normalizedRoute = normalizePagePath(route.pathname) const normalizedRoute = normalizePagePath(route.pathname)
const parentPageInfo = pageInfos.get(page) as PageInfo
const metadata = exportResult.byPath.get( const metadata = exportResult.byPath.get(
route.pathname route.pathname
...@@ -3427,13 +3442,38 @@ export default async function build( ...@@ -3427,13 +3442,38 @@ export default async function build(
} }
} }
pageInfos.set(route.pathname, { if (route.pathname === page) {
...(pageInfos.get(route.pathname) as PageInfo), // The route pattern entry (for example `/blog/[slug]`) is
isDynamicAppRoute: true, // also present in `dynamicPrerenderedRoutes`. Keep updating
// if PPR is turned on and the route contains a dynamic segment, // the parent entry in place so it retains its `ssgPageRoutes`
// we assume it'll be partially prerendered // subtree; if we rewrote it like a concrete child route we
hasPostponed: isRoutePPREnabled, // would lose the generated child paths from the build output.
}) pageInfos.set(page, {
...(pageInfos.get(page) as PageInfo),
initialCacheControl: cacheControl,
isDynamicAppRoute: true,
// if PPR is turned on and the route contains a dynamic segment,
// we assume it'll be partially prerendered
hasPostponed: isRoutePPREnabled,
})
} else {
// Concrete generated paths inherit the parent route's base
// metadata, but they should not themselves print a nested
// subtree. Clearing `ssgPageRoutes` here lets the tree view
// classify the child path with its own symbol only once.
pageInfos.set(route.pathname, {
...parentPageInfo,
...(pageInfos.get(route.pathname) as PageInfo),
ssgPageRoutes: null,
ssgPageDurations: undefined,
pageDuration: undefined,
initialCacheControl: cacheControl,
isDynamicAppRoute: true,
// if PPR is turned on and the route contains a dynamic segment,
// we assume it'll be partially prerendered
hasPostponed: isRoutePPREnabled,
})
}
const fallbackMode = getFallbackMode(route) const fallbackMode = getFallbackMode(route)
......
...@@ -212,6 +212,48 @@ export interface PageInfo { ...@@ -212,6 +212,48 @@ export interface PageInfo {
export type PageInfos = Map<string, PageInfo> export type PageInfos = Map<string, PageInfo>
function getTreeViewSymbol(
item: string,
pageInfo: PageInfo | undefined
): string {
if (item === '/_app' || item === '/_app.server') {
return ' '
}
if (isEdgeRuntime(pageInfo?.runtime)) {
return 'ƒ'
}
if (pageInfo?.isRoutePPREnabled) {
if (
// If the page has an empty static shell, then it's equivalent to a
// dynamic page
pageInfo?.hasEmptyStaticShell ||
// ensure we don't mark dynamic paths that postponed as being dynamic
// since in this case we're able to partially prerender it
(pageInfo.isDynamicAppRoute && !pageInfo.hasPostponed)
) {
return 'ƒ'
}
if (!pageInfo?.hasPostponed) {
return '○'
}
return '◐'
}
if (pageInfo?.isStatic) {
return '○'
}
if (pageInfo?.isSSG) {
return '●'
}
return 'ƒ'
}
export interface RoutesUsingEdgeRuntime { export interface RoutesUsingEdgeRuntime {
[route: string]: 0 [route: string]: 0
} }
...@@ -333,34 +375,7 @@ export async function printTreeView( ...@@ -333,34 +375,7 @@ export async function printTreeView(
(pageInfo?.pageDuration || 0) + (pageInfo?.pageDuration || 0) +
(pageInfo?.ssgPageDurations?.reduce((a, b) => a + (b || 0), 0) || 0) (pageInfo?.ssgPageDurations?.reduce((a, b) => a + (b || 0), 0) || 0)
let symbol: string const symbol = getTreeViewSymbol(item, pageInfo)
if (item === '/_app' || item === '/_app.server') {
symbol = ' '
} else if (isEdgeRuntime(pageInfo?.runtime)) {
symbol = 'ƒ'
} else if (pageInfo?.isRoutePPREnabled) {
if (
// If the page has an empty static shell, then it's equivalent to a
// dynamic page
pageInfo?.hasEmptyStaticShell ||
// ensure we don't mark dynamic paths that postponed as being dynamic
// since in this case we're able to partially prerender it
(pageInfo.isDynamicAppRoute && !pageInfo.hasPostponed)
) {
symbol = 'ƒ'
} else if (!pageInfo?.hasPostponed) {
symbol = '○'
} else {
symbol = '◐'
}
} else if (pageInfo?.isStatic) {
symbol = '○'
} else if (pageInfo?.isSSG) {
symbol = '●'
} else {
symbol = 'ƒ'
}
const displayPath = getTreeViewDisplayPath(item) const displayPath = getTreeViewDisplayPath(item)
...@@ -446,12 +461,16 @@ export async function printTreeView( ...@@ -446,12 +461,16 @@ export async function printTreeView(
routes.forEach( routes.forEach(
({ route, duration, avgDuration }, index, { length }) => { ({ route, duration, avgDuration }, index, { length }) => {
const innerSymbol = index === length - 1 ? '└' : '├' const innerSymbol = index === length - 1 ? '└' : '├'
// Generated child paths can have more precise metadata than the
// parent route pattern, so prefer the child entry when present.
const routePageInfo = pageInfos.get(route) ?? pageInfo
const routeSymbol = getTreeViewSymbol(route, routePageInfo)
const initialCacheControl = const initialCacheControl =
pageInfos.get(route)?.initialCacheControl pageInfos.get(route)?.initialCacheControl
messages.push([ messages.push([
`${contSymbol} ${innerSymbol} ${route}${ `${contSymbol} ${innerSymbol} ${routeSymbol} ${route}${
duration > MIN_DURATION duration > MIN_DURATION
? ` (${getPrettyDuration(duration)})` ? ` (${getPrettyDuration(duration)})`
: '' : ''
......
...@@ -44,13 +44,13 @@ describe('build-output-ssg-bailout', () => { ...@@ -44,13 +44,13 @@ describe('build-output-ssg-bailout', () => {
┌ ○ /_not-found ┌ ○ /_not-found
├ ƒ /ssg-bailout-partial/[id] ├ ƒ /ssg-bailout-partial/[id]
├ ● /ssg-bailout-partial/[id] ├ ● /ssg-bailout-partial/[id]
│ ├ /ssg-bailout-partial/2 │ ├ ● /ssg-bailout-partial/2
│ └ /ssg-bailout-partial/3 │ └ ● /ssg-bailout-partial/3
├ ƒ /ssg-bailout/[id] ├ ƒ /ssg-bailout/[id]
└ ● /ssg/[id] └ ● /ssg/[id]
├ /ssg/1 ├ ● /ssg/1
├ /ssg/2 ├ ● /ssg/2
└ /ssg/3 └ ● /ssg/3
○ (Static) prerendered as static content ○ (Static) prerendered as static content
......
...@@ -68,6 +68,27 @@ describe('build-output-tree-view', () => { ...@@ -68,6 +68,27 @@ describe('build-output-tree-view', () => {
`) `)
}) })
}) })
describe('with generated app routes that mix static and partial outputs', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, '../../../e2e/app-dir/cache-components'),
skipStart: true,
env: {
__NEXT_PRIVATE_DETERMINISTIC_BUILD_OUTPUT: '1',
},
})
beforeAll(() => next.build())
it('should show child route symbols for generated app paths', async () => {
expect(getTreeView(next.cliOutput)).toContain(
`├ ◐ /params/semantics/[lowcard]/[highcard]/layout-has/server
│ ├ ◐ /params/semantics/[lowcard]/[highcard]/layout-has/server
│ ├ ◐ /params/semantics/one/[highcard]/layout-has/server
│ └ ○ /params/semantics/one/build/layout-has/server`
)
})
})
}) })
function getTreeView(cliOutput: string): string { function getTreeView(cliOutput: string): string {
......
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