Unverified Commit 4bee1b4c authored by Aurora Scharff's avatar Aurora Scharff Committed by GitHub

fix: classify collapsed generated paths from child routes (#99864)

### What

Fix the build route table so a collapsed generated-path row uses the
shared symbol of the concrete paths it represents. The Maintainer Agent
regression test now expects the Static symbol.

### Before

The generated paths are static, but the collapsed row inherits the
Partial Prerender symbol from the dynamic route pattern:

```text
└   /blog/[...slug]
  ├ ◐ /blog/[...slug]
  ├ ○ /blog/post-1
  ├ ○ /blog/post-2
  └ ◐ [+10 more paths]
```

### After

The collapsed row uses the shared Static symbol from the generated paths
it represents:

```text
└   /blog/[...slug]
  ├ ◐ /blog/[...slug]
  ├ ○ /blog/post-1
  ├ ○ /blog/post-2
  └ ○ [+10 more paths]
```

The route pattern remains Partial Prerender because it can still handle
paths outside `generateStaticParams`. Only the collapsed generated-path
row changes.

### Why

With Cache Components, Partial Prefetching, and `ensureStatic =
'navigation'`, a catch-all route can have a Partial Prerender route
pattern while every generated path is complete and static. The synthetic
`[+N more paths]` label has no `pageInfos` entry, so it previously fell
back to the route pattern and printed Partial Prerender for those static
paths.

### How

Compute the hidden paths’ symbols in both the regular and
duration-sorted truncation branches. Use the shared child symbol when
every hidden path agrees; if the hidden paths have mixed symbols,
preserve the conservative route-pattern fallback.

The regression test asserts the real `next build` CLI output and
verifies that every generated path produces complete static HTML.

### Documentation

The Building guide introduces the collapsed `[+N more paths]` notation
at first use and shows the correct symbol as the rendering
classification changes.

### Validation

- `NEXT_SKIP_ISOLATE=1 pnpm test-start-turbo
test/e2e/app-dir/build-output-truncated-generated-paths/` — 2 passed
- `NEXT_SKIP_ISOLATE=1 pnpm test-start-turbo
test/production/build-output/build-output.test.ts` — 10 passed, 2
skipped
- `pnpm --filter=next build` — passed
- Pre-commit Prettier and ESLint checks passed
- Prettier check for the documentation — passed

Maintainer investigation:
https://next-maintainer-agent.vercel.tools/investigations/feedback/64
DX Agent feedback:
https://dxagent.labs.vercel.dev/dashboard/feedback/3fbc3904-2843-4eb6-9033-312f4306b66b

Prepared in fork:
https://github.com/vercel-labs/next.js-experimental/pull/237

---------
Co-authored-by: 's avatarvercel-gh-bot-3[bot] <282332853+vercel-gh-bot-3[bot]@users.noreply.github.com>
parent b5873b76
......@@ -234,7 +234,7 @@ The route now has a segment-wide fallback from `loading.js`. To prerender pages
export async function generateStaticParams() {
const res = await fetch('https://api.example.com/products')
const products = await res.json()
return products.map((product) => ({ id: product.id }))
return products.slice(0, 12).map((product) => ({ id: product.id }))
}
export default async function Page(props: PageProps<'/products/[id]'>) {
......@@ -249,7 +249,7 @@ export default async function Page(props: PageProps<'/products/[id]'>) {
export async function generateStaticParams() {
const res = await fetch('https://api.example.com/products')
const products = await res.json()
return products.map((product) => ({ id: product.id }))
return products.slice(0, 12).map((product) => ({ id: product.id }))
}
export default async function Page({ params }) {
......@@ -276,13 +276,13 @@ Route (app)
├ ◐ /products/[id] # Fallback row
├ ◐ /products/1 # Product content streams into the static shell
├ ◐ /products/2
└ ◐ /products/3
└ ◐ [+10 more paths]
○ (Static) prerendered as static content
◐ (Partial Prerender) prerendered as static HTML with dynamic server-streamed content
```
The unmarked `/products/[id]` row groups the route outputs beneath it. Each indented row stays `◐`. The `loading.js` fallback is prerendered, then the product loads at request time and streams into that shell.
The unmarked `/products/[id]` row groups the route outputs beneath it. When there are more prerendered paths than fit in the table, Next.js prints a short list ending with `[+N more paths]`. Each indented row stays `◐`. The `loading.js` fallback is prerendered, then the product loads at request time and streams into that shell.
> **Good to know**: `generateStaticParams` is optional. Use it when a set of pathnames is known at build time and worth prerendering. With Cache Components, it must return at least one param. An empty array causes a [build error](/docs/messages/empty-generate-static-params).
......@@ -294,7 +294,7 @@ Choose the error's `[cache]` option when the product lookup can be reused across
export async function generateStaticParams() {
const res = await fetch('https://api.example.com/products')
const products = await res.json()
return products.map((product) => ({ id: product.id }))
return products.slice(0, 12).map((product) => ({ id: product.id }))
}
async function getProduct(id: string) {
......@@ -314,7 +314,7 @@ export default async function Page(props: PageProps<'/products/[id]'>) {
export async function generateStaticParams() {
const res = await fetch('https://api.example.com/products')
const products = await res.json()
return products.map((product) => ({ id: product.id }))
return products.slice(0, 12).map((product) => ({ id: product.id }))
}
async function getProduct(id) {
......@@ -340,7 +340,7 @@ Route (app)
├ ◐ /products/[id] # Fallback row
├ ○ /products/1 # Full HTML prerender
├ ○ /products/2
└ ○ /products/3
└ ○ [+10 more paths]
○ (Static) prerendered as static content
◐ (Partial Prerender) prerendered as static HTML with dynamic server-streamed content
......@@ -348,8 +348,6 @@ Route (app)
The `/products/[id]` fallback represents product IDs not returned by `generateStaticParams`. It stays `◐` because the build does not know every product ID. On the first visit to an unlisted product, [Partial Prefetching](/docs/app/api-reference/config/next-config-js/partialPrefetching) serves the `loading.js` fallback immediately while Next.js renders the page for that ID and stores it in the [ISR cache](/docs/app/glossary#incremental-static-regeneration-isr). Later visits receive the completed page instead of the fallback. See [ISR with Cache Components](/docs/app/guides/incremental-static-regeneration-cache-components) for the complete upgrade flow.
When there are more prerendered paths than fit in the table, Next.js prints a short list ending with `[+N more paths]`.
Routes that contain cached functions or components can also show `Revalidate` and `Expire` columns. A route reports the shortest `revalidate` and `expire` across all the caches it contains. Caches use the [`default` profile](/docs/app/api-reference/functions/cacheLife#preset-cache-profiles) when there is no explicit [`cacheLife`](/docs/app/api-reference/functions/cacheLife) call. A `/products` listing page that renders the same cached data produces this output:
```bash filename="Terminal"
......@@ -361,7 +359,7 @@ Route (app) Revalidate Expire
├ ◐ /products/[id]
├ ○ /products/1 15m 1y
├ ○ /products/2 15m 1y
└ ○ /products/3 15m 1y
└ ○ [+10 more paths]
```
The default [`use cache` profile](/docs/app/api-reference/functions/cacheLife#preset-cache-profiles) revalidates after 15 minutes. The route's default [`expireTime`](/docs/app/api-reference/config/next-config-js/expireTime) is one year, so the table shows `15m` and `1y`. You can configure both values in `next.config.ts`.
......@@ -380,7 +378,7 @@ export const instant = false
export async function generateStaticParams() {
const res = await fetch('https://api.example.com/products')
const products = await res.json()
return products.map((product) => ({ id: product.id }))
return products.slice(0, 12).map((product) => ({ id: product.id }))
}
export default async function Page(props: PageProps<'/products/[id]'>) {
......@@ -402,7 +400,7 @@ export const instant = false
export async function generateStaticParams() {
const res = await fetch('https://api.example.com/products')
const products = await res.json()
return products.map((product) => ({ id: product.id }))
return products.slice(0, 12).map((product) => ({ id: product.id }))
}
export default async function Page({ params }) {
......@@ -430,7 +428,7 @@ Route (app)
├ ƒ /products/[id] # Empty fallback for unlisted IDs
├ ƒ /products/1 # Rendered on request with no HTML prerender
├ ƒ /products/2
└ ƒ /products/3
└ ƒ [+10 more paths]
○ (Static) prerendered as static content
ƒ (Dynamic) server-rendered on demand
......
......@@ -443,9 +443,22 @@ export async function printTreeView(
const totalRoutes = pageInfo.ssgPageRoutes.length
const contSymbol = i === arr.length - 1 ? ' ' : '│'
// HERE
const getRouteSymbol = (route: string) =>
getTreeViewSymbol(route, pageInfos.get(route) ?? pageInfo)
const getSharedRouteSymbol = (routes: string[]) => {
const firstSymbol = routes[0] ? getRouteSymbol(routes[0]) : undefined
return routes.every((route) => getRouteSymbol(route) === firstSymbol)
? firstSymbol
: undefined
}
let routes: { route: string; duration: number; avgDuration?: number }[]
let routes: {
route: string
duration: number
avgDuration?: number
symbol?: string
}[]
if (pageInfo.ssgPageDurations?.some((d) => d > MIN_DURATION)) {
const previewPages = totalRoutes === 8 ? 8 : Math.min(totalRoutes, 7)
const routesWithDuration = pageInfo.ssgPageRoutes
......@@ -472,6 +485,9 @@ export async function printTreeView(
route: `[+${remaining} more paths]`,
duration: 0,
avgDuration,
symbol: getSharedRouteSymbol(
remainingRoutes.map(({ route }) => route)
),
})
}
} else {
......@@ -481,17 +497,27 @@ export async function printTreeView(
.map((route) => ({ route, duration: 0 }))
if (totalRoutes > previewPages) {
const remaining = totalRoutes - previewPages
routes.push({ route: `[+${remaining} more paths]`, duration: 0 })
routes.push({
route: `[+${remaining} more paths]`,
duration: 0,
symbol: getSharedRouteSymbol(
pageInfo.ssgPageRoutes.slice(previewPages)
),
})
}
}
routes.forEach(
({ route, duration, avgDuration }, index, { length }) => {
(
{ route, duration, avgDuration, symbol: sharedSymbol },
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)
// parent route pattern. A summary row can use that metadata only
// when all of the collapsed paths have the same symbol.
const routeSymbol = sharedSymbol ?? getRouteSymbol(route)
usedSymbols.add(routeSymbol)
const initialCacheControl =
......
const slugs = Array.from({ length: 12 }, (_, index) => `post-${index + 1}`)
export function generateStaticParams() {
return slugs.map((slug) => ({ slug: [slug] }))
}
async function getPost(slug: string) {
'use cache'
return `content for ${slug}`
}
export default async function Page({
params,
}: {
params: Promise<{ slug: string[] }>
}) {
const { slug } = await params
const content = await getPost(slug.join('/'))
return <p id="content">{content}</p>
}
import type { ReactNode } from 'react'
export const ensureStatic = 'navigation'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>index</p>
}
import { nextTestSetup } from 'e2e-utils'
// This suite only asserts `next build` output, so it is start-mode only.
// @force-gate start
describe('build output - truncated generated paths', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
env: {
__NEXT_PRIVATE_DETERMINISTIC_BUILD_OUTPUT: '1',
},
})
beforeAll(() => next.build())
it('marks the collapsed generated paths as static', async () => {
expect(getTreeView(next.cliOutput)).toContain(
`└ /blog/[...slug]
├ ◐ /blog/[...slug]
├ ○ /blog/post-1
├ ○ /blog/post-2
└ ○ [+10 more paths]`
)
})
it('writes complete static HTML for every generated path', async () => {
for (let index = 1; index <= 12; index++) {
const slug = `post-${index}`
const html = await next.readFile(`.next/server/app/blog/${slug}.html`)
expect(html).toContain(`<p id="content">content for ${slug}</p>`)
expect(html).toContain('</html>')
}
})
})
function getTreeView(cliOutput: string): string {
let foundStart = false
const lines: string[] = []
for (const line of cliOutput.split('\n')) {
foundStart ||= line.startsWith('Route ')
if (foundStart) {
lines.push(line)
}
}
return lines.join('\n').trim()
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
cacheComponents: true,
partialPrefetching: true,
}
export default nextConfig
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