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(
for (const route of staticPrerenderedRoutes) {
if (isDynamicRoute(page) && route.pathname === page) continue
const pageInfo = pageInfos.get(page) as PageInfo
const {
metadata = {},
hasEmptyStaticShell,
......@@ -3225,8 +3226,18 @@ export default async function build(
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, {
...pageInfo,
...(pageInfos.get(route.pathname) as PageInfo),
ssgPageRoutes: null,
ssgPageDurations: undefined,
pageDuration: undefined,
isDynamicAppRoute: false,
hasPostponed,
hasEmptyStaticShell,
initialCacheControl: cacheControl,
......@@ -3286,7 +3297,7 @@ export default async function build(
hasRevalidateZero = true
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
// during prerendering.
ssgPageRoutesSet.delete(route.pathname)
......@@ -3299,10 +3310,13 @@ export default async function build(
}
pageInfos.set(page, {
...pageInfo,
...currentPageInfo,
ssgPageRoutes: Array.from(ssgPageRoutesSet),
// 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 {
// we might have determined during prerendering that this page
......@@ -3336,6 +3350,7 @@ export default async function build(
for (const route of dynamicPrerenderedRoutes) {
const normalizedRoute = normalizePagePath(route.pathname)
const parentPageInfo = pageInfos.get(page) as PageInfo
const metadata = exportResult.byPath.get(
route.pathname
......@@ -3427,13 +3442,38 @@ export default async function build(
}
}
pageInfos.set(route.pathname, {
...(pageInfos.get(route.pathname) as PageInfo),
isDynamicAppRoute: true,
// if PPR is turned on and the route contains a dynamic segment,
// we assume it'll be partially prerendered
hasPostponed: isRoutePPREnabled,
})
if (route.pathname === page) {
// The route pattern entry (for example `/blog/[slug]`) is
// also present in `dynamicPrerenderedRoutes`. Keep updating
// the parent entry in place so it retains its `ssgPageRoutes`
// subtree; if we rewrote it like a concrete child route we
// 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)
......
......@@ -212,6 +212,48 @@ export interface 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 {
[route: string]: 0
}
......@@ -333,34 +375,7 @@ export async function printTreeView(
(pageInfo?.pageDuration || 0) +
(pageInfo?.ssgPageDurations?.reduce((a, b) => a + (b || 0), 0) || 0)
let symbol: string
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 symbol = getTreeViewSymbol(item, pageInfo)
const displayPath = getTreeViewDisplayPath(item)
......@@ -446,12 +461,16 @@ export async function printTreeView(
routes.forEach(
({ route, duration, avgDuration }, index, { length }) => {
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 =
pageInfos.get(route)?.initialCacheControl
messages.push([
`${contSymbol} ${innerSymbol} ${route}${
`${contSymbol} ${innerSymbol} ${routeSymbol} ${route}${
duration > MIN_DURATION
? ` (${getPrettyDuration(duration)})`
: ''
......
......@@ -44,13 +44,13 @@ describe('build-output-ssg-bailout', () => {
┌ ○ /_not-found
├ ƒ /ssg-bailout-partial/[id]
├ ● /ssg-bailout-partial/[id]
│ ├ /ssg-bailout-partial/2
│ └ /ssg-bailout-partial/3
│ ├ ● /ssg-bailout-partial/2
│ └ ● /ssg-bailout-partial/3
├ ƒ /ssg-bailout/[id]
└ ● /ssg/[id]
├ /ssg/1
├ /ssg/2
└ /ssg/3
├ ● /ssg/1
├ ● /ssg/2
└ ● /ssg/3
○ (Static) prerendered as static content
......
......@@ -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 {
......
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