Unverified Commit 1498b366 authored by David Alexandru Ilie's avatar David Alexandru Ilie Committed by GitHub

build: show non-200 prerender statuses

parent b18acf67
...@@ -3460,6 +3460,7 @@ export default async function build( ...@@ -3460,6 +3460,7 @@ export default async function build(
hasEmptyStaticShell, hasEmptyStaticShell,
hasPostponed, hasPostponed,
hasStaticRsc, hasStaticRsc,
prerenderStatus,
} = routeResult ?? {} } = routeResult ?? {}
const cacheControl = getCacheControl( const cacheControl = getCacheControl(
...@@ -3482,6 +3483,11 @@ export default async function build( ...@@ -3482,6 +3483,11 @@ export default async function build(
hasPostponed, hasPostponed,
hasEmptyStaticShell, hasEmptyStaticShell,
initialCacheControl: cacheControl, initialCacheControl: cacheControl,
prerenderStatus:
cacheControl.revalidate !== 0 &&
route.pathname !== UNDERSCORE_NOT_FOUND_ROUTE
? prerenderStatus
: undefined,
}) })
// update the page (eg /blog/[slug]) to also have the postpone metadata // update the page (eg /blog/[slug]) to also have the postpone metadata
...@@ -3748,6 +3754,11 @@ export default async function build( ...@@ -3748,6 +3754,11 @@ export default async function build(
// 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: isRoutePPREnabled, hasPostponed: isRoutePPREnabled,
prerenderStatus:
cacheControl.revalidate !== 0 &&
route.pathname !== UNDERSCORE_NOT_FOUND_ROUTE
? routeResult?.prerenderStatus
: undefined,
}) })
} }
......
...@@ -218,6 +218,8 @@ export interface PageInfo { ...@@ -218,6 +218,8 @@ export interface PageInfo {
hasEmptyStaticShell?: boolean hasEmptyStaticShell?: boolean
hasPostponed?: boolean hasPostponed?: boolean
isDynamicAppRoute?: boolean isDynamicAppRoute?: boolean
/** The HTTP status produced while prerendering this route. */
prerenderStatus?: number
} }
export type PageInfos = Map<string, PageInfo> export type PageInfos = Map<string, PageInfo>
...@@ -264,6 +266,11 @@ function getTreeViewSymbol( ...@@ -264,6 +266,11 @@ function getTreeViewSymbol(
return 'ƒ' return 'ƒ'
} }
function getPrerenderStatusAnnotation(pageInfo: PageInfo | undefined): string {
const status = pageInfo?.prerenderStatus
return status !== undefined && status !== 200 ? ` [status: ${status}]` : ''
}
export interface RoutesUsingEdgeRuntime { export interface RoutesUsingEdgeRuntime {
[route: string]: 0 [route: string]: 0
} }
...@@ -389,6 +396,9 @@ export async function printTreeView( ...@@ -389,6 +396,9 @@ export async function printTreeView(
const hasChildRoutes = Boolean(pageInfo?.ssgPageRoutes?.length) const hasChildRoutes = Boolean(pageInfo?.ssgPageRoutes?.length)
const displayPath = getTreeViewDisplayPath(item) const displayPath = getTreeViewDisplayPath(item)
const prerenderStatusAnnotation = hasChildRoutes
? ''
: getPrerenderStatusAnnotation(pageInfo)
if (hasGSPAndRevalidateZero.has(item)) { if (hasGSPAndRevalidateZero.has(item)) {
usedSymbols.add('ƒ') usedSymbols.add('ƒ')
...@@ -414,7 +424,7 @@ export async function printTreeView( ...@@ -414,7 +424,7 @@ export async function printTreeView(
} }
messages.push([ messages.push([
`${border} ${hasChildRoutes ? ' ' : symbol} ${displayPath}${ `${border} ${hasChildRoutes ? ' ' : symbol} ${displayPath}${prerenderStatusAnnotation}${
totalDuration > MIN_DURATION totalDuration > MIN_DURATION
? ` (${getPrettyDuration(totalDuration)})` ? ` (${getPrettyDuration(totalDuration)})`
: '' : ''
...@@ -481,12 +491,15 @@ export async function printTreeView( ...@@ -481,12 +491,15 @@ export async function printTreeView(
const routePageInfo = pageInfos.get(route) ?? pageInfo const routePageInfo = pageInfos.get(route) ?? pageInfo
const routeSymbol = getTreeViewSymbol(route, routePageInfo) const routeSymbol = getTreeViewSymbol(route, routePageInfo)
usedSymbols.add(routeSymbol) usedSymbols.add(routeSymbol)
const childStatusAnnotation = getPrerenderStatusAnnotation(
pageInfos.get(route)
)
const initialCacheControl = const initialCacheControl =
pageInfos.get(route)?.initialCacheControl pageInfos.get(route)?.initialCacheControl
messages.push([ messages.push([
`${contSymbol} ${innerSymbol} ${routeSymbol} ${route}${ `${contSymbol} ${innerSymbol} ${routeSymbol} ${route}${childStatusAnnotation}${
duration > MIN_DURATION duration > MIN_DURATION
? ` (${getPrettyDuration(duration)})` ? ` (${getPrettyDuration(duration)})`
: '' : ''
......
...@@ -848,6 +848,9 @@ async function exportAppImpl( ...@@ -848,6 +848,9 @@ async function exportAppImpl(
if (typeof result.metadata !== 'undefined') { if (typeof result.metadata !== 'undefined') {
info.metadata = result.metadata info.metadata = result.metadata
} }
if (typeof result.prerenderStatus !== 'undefined') {
info.prerenderStatus = result.prerenderStatus
}
if (typeof result.hasEmptyStaticShell !== 'undefined') { if (typeof result.hasEmptyStaticShell !== 'undefined') {
info.hasEmptyStaticShell = result.hasEmptyStaticShell info.hasEmptyStaticShell = result.hasEmptyStaticShell
......
...@@ -252,6 +252,9 @@ export async function exportAppPage( ...@@ -252,6 +252,9 @@ export async function exportAppPage(
segmentPaths: meta.segmentPaths, segmentPaths: meta.segmentPaths,
prefetchHints: meta.prefetchHints, prefetchHints: meta.prefetchHints,
}, },
// Keep the status available to build diagnostics even when deployment
// metadata is filtered in environments without Next.js support.
prerenderStatus: status,
hasEmptyStaticShell: Boolean(postponed) && html === '', hasEmptyStaticShell: Boolean(postponed) && html === '',
hasPostponed: Boolean(postponed), hasPostponed: Boolean(postponed),
hasPendingUi: hasPendingUi ?? false, hasPendingUi: hasPendingUi ?? false,
......
...@@ -69,6 +69,8 @@ export type ExportRouteResult = ...@@ -69,6 +69,8 @@ export type ExportRouteResult =
| { | {
cacheControl: CacheControl cacheControl: CacheControl
metadata?: Partial<RouteMetadata> metadata?: Partial<RouteMetadata>
/** The HTTP status produced while prerendering this route. */
prerenderStatus?: number
ssgNotFound?: boolean ssgNotFound?: boolean
hasEmptyStaticShell?: boolean hasEmptyStaticShell?: boolean
hasPostponed?: boolean hasPostponed?: boolean
...@@ -144,6 +146,10 @@ export type ExportAppResult = { ...@@ -144,6 +146,10 @@ export type ExportAppResult = {
* The metadata for the page. * The metadata for the page.
*/ */
metadata?: Partial<RouteMetadata> metadata?: Partial<RouteMetadata>
/**
* The HTTP status produced while prerendering the page.
*/
prerenderStatus?: number
/** /**
* If the page has an empty static shell when using PPR. * If the page has an empty static shell when using PPR.
*/ */
......
...@@ -69,6 +69,34 @@ describe('build-output-tree-view', () => { ...@@ -69,6 +69,34 @@ describe('build-output-tree-view', () => {
}) })
}) })
describe('with a non-200 prerendered app route', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixtures/prerender-status'),
skipStart: true,
env: {
__NEXT_PRIVATE_DETERMINISTIC_BUILD_OUTPUT: '1',
},
})
beforeAll(() => next.build())
it('shows a known non-200 status on the user route only', () => {
const treeView = getTreeView(next.cliOutput)
expect(treeView).toContain('◐ /error-shell [status: 404]')
expect(treeView).toContain('◐ /healthy-shell')
expect(treeView).not.toContain('/healthy-shell [status:')
expect(treeView).not.toContain('/_not-found [status:')
})
it('does not change the runtime response statuses', async () => {
await next.start()
expect((await next.fetch('/error-shell')).status).toBe(404)
expect((await next.fetch('/healthy-shell')).status).toBe(200)
})
})
describe('with generated app routes that mix static and partial outputs', () => { describe('with generated app routes that mix static and partial outputs', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: path.join(__dirname, '../../../e2e/app-dir/cache-components'), files: path.join(__dirname, '../../../e2e/app-dir/cache-components'),
......
import { notFound } from 'next/navigation'
import { connection } from 'next/server'
export async function generateMetadata() {
await connection()
return { title: 'Runtime metadata' }
}
export default function ErrorShellPage() {
return notFound()
}
import { Suspense } from 'react'
import { connection } from 'next/server'
export async function generateMetadata() {
await connection()
return { title: 'Runtime metadata' }
}
async function RuntimeMarker() {
await connection()
return <span>Runtime content</span>
}
export default function HealthyShellPage() {
return (
<p>
Healthy shell
<Suspense fallback={<span>Loading runtime content</span>}>
<RuntimeMarker />
</Suspense>
</p>
)
}
export default function RootLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
export default function NotFound() {
return <p>Not found</p>
}
export default function Home() {
return <p>Build-output status test</p>
}
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