Commit e8fed69a authored by Jiachi Liu's avatar Jiachi Liu

fix: skip collecting metadata for app-error in webpack (#85892)

parent 14034b70
...@@ -38,6 +38,7 @@ import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../../../client/components/built ...@@ -38,6 +38,7 @@ import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../../../client/components/built
import type { Compilation } from 'webpack' import type { Compilation } from 'webpack'
import { createAppRouteCode } from './create-app-route-code' import { createAppRouteCode } from './create-app-route-code'
import { MissingDefaultParallelRouteError } from '../../../../shared/lib/errors/missing-default-parallel-route-error' import { MissingDefaultParallelRouteError } from '../../../../shared/lib/errors/missing-default-parallel-route-error'
import { normalizePathSep } from '../../../../shared/lib/page-path/normalize-path-sep'
export type AppLoaderOptions = { export type AppLoaderOptions = {
name: string name: string
...@@ -87,7 +88,7 @@ const PARALLEL_VIRTUAL_SEGMENT = 'slot$' ...@@ -87,7 +88,7 @@ const PARALLEL_VIRTUAL_SEGMENT = 'slot$'
const defaultGlobalErrorPath = const defaultGlobalErrorPath =
'next/dist/client/components/builtin/global-error.js' 'next/dist/client/components/builtin/global-error.js'
const defaultNotFoundPath = 'next/dist/client/components/builtin/not-found.js' const defaultNotFoundPath = 'next/dist/client/components/builtin/not-found.js'
const defaultEmptyStubPath = 'next/dist/client/components/builtin/empty-stub' const defaultEmptyStubPath = 'next/dist/client/components/builtin/empty-stub.js'
const defaultLayoutPath = 'next/dist/client/components/builtin/layout.js' const defaultLayoutPath = 'next/dist/client/components/builtin/layout.js'
const defaultGlobalNotFoundPath = const defaultGlobalNotFoundPath =
'next/dist/client/components/builtin/global-not-found.js' 'next/dist/client/components/builtin/global-not-found.js'
...@@ -176,9 +177,7 @@ async function createTreeCodeFromPath( ...@@ -176,9 +177,7 @@ async function createTreeCodeFromPath(
async function resolveAdjacentParallelSegments( async function resolveAdjacentParallelSegments(
segmentPath: string segmentPath: string
): Promise<string[]> { ): Promise<string[]> {
const absoluteSegmentPath = await resolveDir( const absoluteSegmentPath = resolveDir(`${appDirPrefix}${segmentPath}`)
`${appDirPrefix}${segmentPath}`
)
if (!absoluteSegmentPath) { if (!absoluteSegmentPath) {
return [] return []
...@@ -232,7 +231,11 @@ async function createTreeCodeFromPath( ...@@ -232,7 +231,11 @@ async function createTreeCodeFromPath(
const routerDirPath = `${appDirPrefix}${segmentPath}` const routerDirPath = `${appDirPrefix}${segmentPath}`
const resolvedRouteDir = resolveDir(routerDirPath) const resolvedRouteDir = resolveDir(routerDirPath)
if (resolvedRouteDir) { if (
resolvedRouteDir &&
// Do not collect metadata for app-error route as it's for generating pure static 500.html
!normalizePathSep(pagePath).endsWith(appErrorPath)
) {
metadata = await createStaticMetadataFromRoute(resolvedRouteDir, { metadata = await createStaticMetadataFromRoute(resolvedRouteDir, {
basePath, basePath,
segment: segmentPath, segment: segmentPath,
......
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: 'my title',
description: 'my description',
metadataBase: 'https://my-domain.com/',
}
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode
}>) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Home() {
return (
<div>
<h1>Hello World</h1>
</div>
)
}
import { nextTestSetup } from 'e2e-utils'
describe('metadata-base-warning', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should not warn metadataBase for static image when metadataBase is set', async () => {
expect(next.cliOutput).not.toContain(
'metadataBase property in metadata export is not set for resolving social open graph or twitter images'
)
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = 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