Skip to content

Commit 1752d79

Browse files
authored
fix: skip collecting metadata for app-error in webpack (#85892)
1 parent f09304a commit 1752d79

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

packages/next/src/build/webpack/loaders/next-app-loader/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../../../client/components/built
3838
import type { Compilation } from 'webpack'
3939
import { createAppRouteCode } from './create-app-route-code'
4040
import { MissingDefaultParallelRouteError } from '../../../../shared/lib/errors/missing-default-parallel-route-error'
41+
import { normalizePathSep } from '../../../../shared/lib/page-path/normalize-path-sep'
4142

4243
export type AppLoaderOptions = {
4344
name: string
@@ -87,7 +88,7 @@ const PARALLEL_VIRTUAL_SEGMENT = 'slot$'
8788
const defaultGlobalErrorPath =
8889
'next/dist/client/components/builtin/global-error.js'
8990
const defaultNotFoundPath = 'next/dist/client/components/builtin/not-found.js'
90-
const defaultEmptyStubPath = 'next/dist/client/components/builtin/empty-stub'
91+
const defaultEmptyStubPath = 'next/dist/client/components/builtin/empty-stub.js'
9192
const defaultLayoutPath = 'next/dist/client/components/builtin/layout.js'
9293
const defaultGlobalNotFoundPath =
9394
'next/dist/client/components/builtin/global-not-found.js'
@@ -176,9 +177,7 @@ async function createTreeCodeFromPath(
176177
async function resolveAdjacentParallelSegments(
177178
segmentPath: string
178179
): Promise<string[]> {
179-
const absoluteSegmentPath = await resolveDir(
180-
`${appDirPrefix}${segmentPath}`
181-
)
180+
const absoluteSegmentPath = resolveDir(`${appDirPrefix}${segmentPath}`)
182181

183182
if (!absoluteSegmentPath) {
184183
return []
@@ -232,7 +231,11 @@ async function createTreeCodeFromPath(
232231
const routerDirPath = `${appDirPrefix}${segmentPath}`
233232
const resolvedRouteDir = resolveDir(routerDirPath)
234233

235-
if (resolvedRouteDir) {
234+
if (
235+
resolvedRouteDir &&
236+
// Do not collect metadata for app-error route as it's for generating pure static 500.html
237+
!normalizePathSep(pagePath).endsWith(appErrorPath)
238+
) {
236239
metadata = await createStaticMetadataFromRoute(resolvedRouteDir, {
237240
basePath,
238241
segment: segmentPath,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { Metadata } from 'next'
2+
3+
export const metadata: Metadata = {
4+
title: 'my title',
5+
description: 'my description',
6+
metadataBase: 'https://my-domain.com/',
7+
}
8+
9+
export default function RootLayout({
10+
children,
11+
}: Readonly<{
12+
children: React.ReactNode
13+
}>) {
14+
return (
15+
<html>
16+
<body>{children}</body>
17+
</html>
18+
)
19+
}
1.62 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Home() {
2+
return (
3+
<div>
4+
<h1>Hello World</h1>
5+
</div>
6+
)
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
describe('metadata-base-warning', () => {
4+
const { next } = nextTestSetup({
5+
files: __dirname,
6+
})
7+
8+
it('should not warn metadataBase for static image when metadataBase is set', async () => {
9+
expect(next.cliOutput).not.toContain(
10+
'metadataBase property in metadata export is not set for resolving social open graph or twitter images'
11+
)
12+
})
13+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {}
5+
6+
module.exports = nextConfig

0 commit comments

Comments
 (0)