Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/next/src/build/adapter/build-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,20 +1089,20 @@ export async function handleBuildComplete({
// Skip static metadata routes only when they are prerendered.
// Dynamic metadata routes (e.g. robots/sitemap using connection())
// should remain app routes in adapter outputs.
// Only skip when the route has concrete prerenders we'll emit as
// static files below. Presence in `dynamicRoutes` only means a
// fallback pattern is registered — the function is still required
// as the parent for those dynamic-route entries.
const isStaticMetadataRoute = isStaticMetadataFile(normalizedPage)
const isPrerenderedMetadataRoute =
prerenderManifest.routes[normalizedPage] ||
prerenderManifest.dynamicRoutes[normalizedPage] ||
config.i18n?.locales?.some((locale) => {
const localePathname = path.posix.join(
'/',
locale,
normalizedPage.slice(1)
)
return (
prerenderManifest.routes[localePathname] ||
prerenderManifest.dynamicRoutes[localePathname]
)
return prerenderManifest.routes[localePathname]
})

if (isStaticMetadataRoute && isPrerenderedMetadataRoute) {
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/app-dir/metadata-static-file-gsp/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function generateStaticParams() {
return [{ id: 'one' }, { id: 'two' }]
}

export default async function Page({
params,
}: {
params: Promise<{ id: string }>
}) {
const { id } = await params
return <p>result: {id}</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { nextTestSetup } from 'e2e-utils'

describe('metadata-static-file-gsp', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
})

if (skipped) {
return
}

it('should build and serve a static metadata file colocated with generateStaticParams', async () => {
await next.render('/results/two')
})
})
6 changes: 6 additions & 0 deletions test/e2e/app-dir/metadata-static-file-gsp/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
import { getCommonMetadataHeadTags } from './utils'

describe('metadata-files-static-output-dynamic-route', () => {
if (process.env.__NEXT_CACHE_COMPONENTS) {
// Cache Components build fails when metadata files are inside a dynamic route.
//
// Route "/dynamic/[id]" has a `generateMetadata` that depends on Request data (`cookies()`, etc...)
// or uncached external data (`fetch(...)`, etc...) when the rest of the route does not.
// See more info here: https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
// Error occurred prerendering page "/dynamic/[id]". Read more: https://nextjs.org/docs/messages/prerender-error
// Export encountered an error on /dynamic/[id]/page: /dynamic/[id], exiting the build.
//
// TODO: Remove this skip when metadata files are supported in dynamic routes for Cache Components.
it.skip('should skip test for Cache Components', () => {})
return
}

const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
Expand Down
Loading