Skip to content

Commit 7417043

Browse files
committed
fix static metadata helpers
1 parent b9d8b13 commit 7417043

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

packages/next/src/build/webpack/plugins/next-trace-entrypoints-plugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import picomatch from 'next/dist/compiled/picomatch'
1818
import { getModuleBuildInfo } from '../loaders/get-module-build-info'
1919
import { getPageFilePath } from '../../entries'
2020
import { resolveExternal } from '../../handle-externals'
21-
import { isStaticMetadataRoutePathname } from '../../../lib/metadata/is-metadata-route'
21+
import { isStaticMetadataRoutePage } from '../../../lib/metadata/is-metadata-route'
2222
import { getCompilationSpan } from '../utils'
2323

2424
const PLUGIN_NAME = 'TraceEntryPointsPlugin'
@@ -243,7 +243,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
243243

244244
const entryIsStaticMetadataRoute =
245245
appDirRelativeEntryPath &&
246-
isStaticMetadataRoutePathname(appDirRelativeEntryPath)
246+
isStaticMetadataRoutePage(appDirRelativeEntryPath)
247247

248248
// Include the client reference manifest in the trace, but not for
249249
// static metadata routes, for which we don't generate those.

packages/next/src/lib/metadata/is-metadata-route.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,24 @@ export function isMetadataRouteFile(
128128
)
129129
}
130130

131-
function isStaticMetadataRoutePage(appDirRelativePath: string) {
131+
export function isStaticMetadataRoutePage(appDirRelativePath: string) {
132132
return isMetadataRouteFile(appDirRelativePath, [], true)
133133
}
134134

135135
// Check if the route is a static metadata route, with /route suffix
136-
// e.g. /robots.txt/route, /sitemap.xml/route, /favicon.ico/route, /manifest/route, /icon/route, etc.
136+
// e.g. /favicon.ico/route, /icon.png/route, etc.
137+
// But skip the text routes like robots.txt since they might also be dynamic.
138+
// Checking route path is not enough to determine if text routes is dynamic.
137139
export function isStaticMetadataRoute(route: string) {
138140
const pathname = route.slice(0, -'/route'.length)
139-
return isAppRouteRoute(route) && isStaticMetadataRoutePage(pathname)
140-
}
141-
142-
// Check if the page is a static metadata route file
143-
// e.g. /robots, /manifest, /favicon.ico, /sitemap.xml, /icon.png, etc.
144-
export function isStaticMetadataRoutePathname(page: string) {
145141
return (
146-
// TODO: avoid directly checking pathnames as they can also be page routes
147-
page === '/robots' ||
148-
page === '/manifest' ||
149-
isStaticMetadataRoutePage(page)
142+
isAppRouteRoute(route) &&
143+
isStaticMetadataRoutePage(pathname) &&
144+
// These routes can either be built by static or dynamic entrypoints,
145+
// so we assume they're dynamic
146+
pathname !== '/robots.txt' &&
147+
pathname !== '/manifest.webmanifest' &&
148+
!pathname.endsWith('/sitemap.xml')
150149
)
151150
}
152151

packages/next/src/server/route-matcher-providers/dev/dev-app-route-route-matcher-provider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isAppRouteRoute } from '../../../lib/is-app-route-route'
77
import { DevAppNormalizers } from '../../normalizers/built/app'
88
import {
99
isMetadataRouteFile,
10-
isStaticMetadataRoutePathname,
10+
isStaticMetadataRoute,
1111
} from '../../../lib/metadata/is-metadata-route'
1212
import { normalizeMetadataPageToRoute } from '../../../lib/metadata/get-metadata-route'
1313
import path from '../../../shared/lib/isomorphic/path'
@@ -53,7 +53,7 @@ export class DevAppRouteRouteMatcherProvider extends FileCacheRouteMatcherProvid
5353
true
5454
)
5555

56-
if (!isStaticMetadataRoutePathname(page) && isEntryMetadataRouteFile) {
56+
if (isEntryMetadataRouteFile && !isStaticMetadataRoute(page)) {
5757
// Matching dynamic metadata routes.
5858
// Add 2 possibilities for both single and multiple routes:
5959
{

0 commit comments

Comments
 (0)