Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
13b13ede
Unverified
Commit
13b13ede
authored
Jan 20, 2026
by
Jiachi Liu
Committed by
GitHub
Jan 20, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[metadata] match the Metadata and ResolvedMetadata type (#88739)
parent
03a1815a
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
272 additions
and
16 deletions
+272
-16
resolve-metadata.ts
packages/next/src/lib/metadata/resolve-metadata.ts
+12
-0
extra-types.ts
packages/next/src/lib/metadata/types/extra-types.ts
+2
-2
metadata-interface.ts
packages/next/src/lib/metadata/types/metadata-interface.ts
+6
-8
opengraph-types.ts
packages/next/src/lib/metadata/types/opengraph-types.ts
+1
-1
twitter-types.ts
packages/next/src/lib/metadata/types/twitter-types.ts
+5
-5
page.js
...dir/metadata-warnings/app/deprecated-other-fields/page.js
+10
-0
metadata-warnings-with-metadatabase.test.ts
...data-warnings/metadata-warnings-with-metadatabase.test.ts
+8
-0
layout.tsx
test/production/app-dir/metadata-spread-types/app/layout.tsx
+27
-0
page.tsx
test/production/app-dir/metadata-spread-types/app/page.tsx
+27
-0
page.tsx
...ion/app-dir/metadata-spread-types/app/spread-all/page.tsx
+19
-0
metadata-spread-types.test.ts
...p-dir/metadata-spread-types/metadata-spread-types.test.ts
+46
-0
next.config.js
test/production/app-dir/metadata-spread-types/next.config.js
+2
-0
metadata-types-compatibility.test.ts
test/unit/metadata-types-compatibility.test.ts
+107
-0
No files found.
packages/next/src/lib/metadata/resolve-metadata.ts
View file @
13b13ede
...
@@ -387,6 +387,18 @@ async function mergeMetadata(
...
@@ -387,6 +387,18 @@ async function mergeMetadata(
newResolvedMetadata
.
other
,
newResolvedMetadata
.
other
,
metadata
.
other
metadata
.
other
)
)
if
(
metadata
.
other
)
{
if
(
'apple-touch-fullscreen'
in
metadata
.
other
)
{
buildState
.
warnings
.
add
(
`Use appleWebApp instead\nRead more: https://nextjs.org/docs/app/api-reference/functions/generate-metadata`
)
}
if
(
'apple-touch-icon-precomposed'
in
metadata
.
other
)
{
buildState
.
warnings
.
add
(
`Use icons.apple instead\nRead more: https://nextjs.org/docs/app/api-reference/functions/generate-metadata`
)
}
}
break
break
case
'metadataBase'
:
case
'metadataBase'
:
newResolvedMetadata
.
metadataBase
=
metadataBase
newResolvedMetadata
.
metadataBase
=
metadataBase
...
...
packages/next/src/lib/metadata/types/extra-types.ts
View file @
13b13ede
...
@@ -92,7 +92,7 @@ export type ResolvedAppleWebApp = {
...
@@ -92,7 +92,7 @@ export type ResolvedAppleWebApp = {
statusBarStyle
?:
'default'
|
'black'
|
'black-translucent'
|
undefined
statusBarStyle
?:
'default'
|
'black'
|
'black-translucent'
|
undefined
}
}
export
type
Facebook
=
FacebookAppId
|
FacebookAdmins
export
type
Facebook
=
FacebookAppId
|
FacebookAdmins
|
ResolvedFacebook
export
type
FacebookAppId
=
{
export
type
FacebookAppId
=
{
appId
:
string
appId
:
string
admins
?:
never
|
undefined
admins
?:
never
|
undefined
...
@@ -106,7 +106,7 @@ export type ResolvedFacebook = {
...
@@ -106,7 +106,7 @@ export type ResolvedFacebook = {
admins
?:
string
[]
|
undefined
admins
?:
string
[]
|
undefined
}
}
export
type
Pinterest
=
PinterestRichPin
export
type
Pinterest
=
PinterestRichPin
|
ResolvedPinterest
export
type
PinterestRichPin
=
{
export
type
PinterestRichPin
=
{
richPin
:
string
|
boolean
richPin
:
string
|
boolean
}
}
...
...
packages/next/src/lib/metadata/types/metadata-interface.ts
View file @
13b13ede
...
@@ -557,9 +557,9 @@ interface Metadata extends DeprecatedMetadataFields {
...
@@ -557,9 +557,9 @@ interface Metadata extends DeprecatedMetadataFields {
* ```
* ```
*/
*/
other
?:
other
?:
|
(
{
|
{
[
name
:
string
]:
string
|
number
|
Array
<
string
|
number
>
[
name
:
string
]:
string
|
number
|
Array
<
string
|
number
>
}
&
DeprecatedMetadataFields
)
}
|
undefined
|
undefined
}
}
...
@@ -567,7 +567,7 @@ interface Metadata extends DeprecatedMetadataFields {
...
@@ -567,7 +567,7 @@ interface Metadata extends DeprecatedMetadataFields {
* ResolvedMetadataWithURLs represents the fully processed metadata after
* ResolvedMetadataWithURLs represents the fully processed metadata after
* defaults are applied and relative URLs are composed with `metadataBase`.
* defaults are applied and relative URLs are composed with `metadataBase`.
*/
*/
interface
ResolvedMetadataWithURLs
extends
DeprecatedMetadataFields
{
interface
ResolvedMetadataWithURLs
{
// origin and base path for absolute urls for various metadata links such as
// origin and base path for absolute urls for various metadata links such as
// opengraph-image
// opengraph-image
metadataBase
:
string
|
null
|
URL
metadataBase
:
string
|
null
|
URL
...
@@ -657,11 +657,9 @@ interface ResolvedMetadataWithURLs extends DeprecatedMetadataFields {
...
@@ -657,11 +657,9 @@ interface ResolvedMetadataWithURLs extends DeprecatedMetadataFields {
// meta name properties
// meta name properties
category
:
null
|
string
category
:
null
|
string
classification
:
null
|
string
classification
:
null
|
string
other
:
other
:
null
|
{
|
null
[
name
:
string
]:
string
|
number
|
Array
<
string
|
number
>
|
({
}
[
name
:
string
]:
string
|
number
|
Array
<
string
|
number
>
}
&
DeprecatedMetadataFields
)
}
}
export
type
WithStringifiedURLs
<
T
>
=
T
extends
URL
export
type
WithStringifiedURLs
<
T
>
=
T
extends
URL
...
...
packages/next/src/lib/metadata/types/opengraph-types.ts
View file @
13b13ede
...
@@ -45,7 +45,7 @@ type OpenGraphMetadata = {
...
@@ -45,7 +45,7 @@ type OpenGraphMetadata = {
images
?:
OGImage
|
Array
<
OGImage
>
|
undefined
images
?:
OGImage
|
Array
<
OGImage
>
|
undefined
audio
?:
OGAudio
|
Array
<
OGAudio
>
|
undefined
audio
?:
OGAudio
|
Array
<
OGAudio
>
|
undefined
videos
?:
OGVideo
|
Array
<
OGVideo
>
|
undefined
videos
?:
OGVideo
|
Array
<
OGVideo
>
|
undefined
url
?:
string
|
URL
|
undefined
url
?:
null
|
string
|
URL
|
undefined
countryName
?:
string
|
undefined
countryName
?:
string
|
undefined
ttl
?:
number
|
undefined
ttl
?:
number
|
undefined
}
}
...
...
packages/next/src/lib/metadata/types/twitter-types.ts
View file @
13b13ede
...
@@ -11,11 +11,11 @@ export type Twitter =
...
@@ -11,11 +11,11 @@ export type Twitter =
type
TwitterMetadata
=
{
type
TwitterMetadata
=
{
// defaults to card="summary"
// defaults to card="summary"
site
?:
string
|
undefined
// username for account associated to the site itself
site
?:
null
|
string
|
undefined
// username for account associated to the site itself
siteId
?:
string
|
undefined
// id for account associated to the site itself
siteId
?:
null
|
string
|
undefined
// id for account associated to the site itself
creator
?:
string
|
undefined
// username for the account associated to the creator of the content on the site
creator
?:
null
|
string
|
undefined
// username for the account associated to the creator of the content on the site
creatorId
?:
string
|
undefined
// id for the account associated to the creator of the content on the site
creatorId
?:
null
|
string
|
undefined
// id for the account associated to the creator of the content on the site
description
?:
string
|
undefined
description
?:
null
|
string
|
undefined
title
?:
string
|
TemplateString
|
undefined
title
?:
string
|
TemplateString
|
undefined
images
?:
TwitterImage
|
Array
<
TwitterImage
>
|
undefined
images
?:
TwitterImage
|
Array
<
TwitterImage
>
|
undefined
}
}
...
...
test/e2e/app-dir/metadata-warnings/app/deprecated-other-fields/page.js
0 → 100644
View file @
13b13ede
export
default
function
Page
()
{
return
'deprecated other fields'
}
export
const
metadata
=
{
other
:
{
'apple-touch-fullscreen'
:
'yes'
,
'apple-touch-icon-precomposed'
:
'/icon.png'
,
},
}
test/e2e/app-dir/metadata-warnings/metadata-warnings-with-metadatabase.test.ts
View file @
13b13ede
...
@@ -70,4 +70,12 @@ describe('app dir - metadata missing metadataBase', () => {
...
@@ -70,4 +70,12 @@ describe('app dir - metadata missing metadataBase', () => {
const
output
=
next
.
cliOutput
.
slice
(
outputLength
)
const
output
=
next
.
cliOutput
.
slice
(
outputLength
)
expect
(
output
).
not
.
toContain
(
'Unsupported metadata viewport'
)
expect
(
output
).
not
.
toContain
(
'Unsupported metadata viewport'
)
})
})
it
(
'should warn for deprecated fields in other property'
,
async
()
=>
{
const
logStartPosition
=
next
.
cliOutput
.
length
await
next
.
fetch
(
'/deprecated-other-fields'
)
const
output
=
getCliOutput
(
logStartPosition
)
expect
(
output
).
toInclude
(
'Use appleWebApp instead'
)
expect
(
output
).
toInclude
(
'Use icons.apple instead'
)
})
})
})
test/production/app-dir/metadata-spread-types/app/layout.tsx
0 → 100644
View file @
13b13ede
import
type
{
Metadata
}
from
'next'
export
const
metadata
:
Metadata
=
{
title
:
'Layout title'
,
description
:
'Layout description'
,
openGraph
:
{
title
:
'Layout OG title'
,
description
:
'Layout OG description'
,
url
:
'https://example.com'
,
siteName
:
'Example Site'
,
},
twitter
:
{
card
:
'summary'
,
title
:
'Layout Twitter title'
,
description
:
'Layout Twitter description'
,
site
:
'@example'
,
creator
:
'@creator'
,
},
}
export
default
function
Layout
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
(
<
html
>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/production/app-dir/metadata-spread-types/app/page.tsx
0 → 100644
View file @
13b13ede
import
type
{
Metadata
,
ResolvingMetadata
}
from
'next'
export
default
function
Page
()
{
return
<
p
>
Spread parent metadata test
</
p
>
}
export
async
function
generateMetadata
(
_
:
unknown
,
parent
:
ResolvingMetadata
):
Promise
<
Metadata
>
{
const
resolvedParent
=
await
parent
return
{
title
:
'Page title'
,
description
:
'Page description'
,
openGraph
:
{
...
resolvedParent
.
openGraph
,
title
:
'Page OG title'
,
description
:
'Page OG description'
,
},
twitter
:
{
...
resolvedParent
.
twitter
,
title
:
'Page Twitter title'
,
description
:
'Page Twitter description'
,
},
}
}
test/production/app-dir/metadata-spread-types/app/spread-all/page.tsx
0 → 100644
View file @
13b13ede
import
type
{
Metadata
,
ResolvingMetadata
}
from
'next'
export
async
function
generateMetadata
(
_
:
unknown
,
parent
:
ResolvingMetadata
):
Promise
<
Metadata
>
{
const
parentMeta
=
await
parent
return
{
...
parentMeta
,
title
:
'Spread all page'
}
}
export
default
function
Page
()
{
return
(
<
div
>
<
h1
>
Spread all page
</
h1
>
<
p
>
This page spreads the entire parent metadata
</
p
>
</
div
>
)
}
test/production/app-dir/metadata-spread-types/metadata-spread-types.test.ts
0 → 100644
View file @
13b13ede
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
createMultiDomMatcher
}
from
'next-test-utils'
describe
(
'metadata spread types'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should allow spreading resolved parent metadata into child metadata'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/'
)
const
matchMultiDom
=
createMultiDomMatcher
(
browser
)
// Verify page title from child's generateMetadata
expect
(
await
browser
.
eval
(
`document.title`
)).
toBe
(
'Page title'
)
// Verify openGraph metadata is correctly merged
await
matchMultiDom
(
'meta'
,
'property'
,
'content'
,
{
'og:title'
:
'Page OG title'
,
'og:description'
:
'Page OG description'
,
'og:url'
:
'https://example.com'
,
'og:site_name'
:
'Example Site'
,
})
// Verify twitter metadata is correctly merged
await
matchMultiDom
(
'meta'
,
'name'
,
'content'
,
{
'twitter:title'
:
'Page Twitter title'
,
'twitter:description'
:
'Page Twitter description'
,
'twitter:site'
:
'@example'
,
'twitter:creator'
:
'@creator'
,
})
})
it
(
'should allow spreading entire resolved parent metadata'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/spread-all'
)
// Verify page title is overridden
expect
(
await
browser
.
eval
(
`document.title`
)).
toBe
(
'Spread all page'
)
// Verify parent metadata is inherited
expect
(
await
browser
.
eval
(
`document.querySelector('meta[name="description"]')?.content`
)
).
toBe
(
'Layout description'
)
})
})
test/production/app-dir/metadata-spread-types/next.config.js
0 → 100644
View file @
13b13ede
/** @type {import('next').NextConfig} */
module
.
exports
=
{}
test/unit/metadata-types-compatibility.test.ts
0 → 100644
View file @
13b13ede
/**
* Type compatibility tests for Metadata and ResolvedMetadata.
*
* These tests verify that ResolvedMetadata properties can be assigned to
* Metadata input types. This is important because users often want to
* extend parent metadata in generateMetadata:
*
* ```ts
* export async function generateMetadata(_, parent: ResolvingMetadata) {
* const resolved = await parent
* return {
* openGraph: {
* ...resolved.openGraph, // Should not cause type errors
* title: 'Override title',
* },
* }
* }
* ```
*
* If these tests fail, it means ResolvedMetadata has properties
* that are not assignable to Metadata (e.g., `null` vs `undefined` mismatch).
*/
import
type
{
Metadata
,
ResolvedMetadata
}
from
'next'
import
{
expectTypeOf
}
from
'expect-type'
// Extract property types for comparison
type
ResolvedOpenGraphUrl
=
NonNullable
<
ResolvedMetadata
[
'openGraph'
]
>
[
'url'
]
type
MetadataOpenGraphUrl
=
NonNullable
<
Metadata
[
'openGraph'
]
>
[
'url'
]
type
ResolvedTwitterSite
=
NonNullable
<
ResolvedMetadata
[
'twitter'
]
>
[
'site'
]
type
MetadataTwitterSite
=
NonNullable
<
Metadata
[
'twitter'
]
>
[
'site'
]
type
ResolvedTwitterCreator
=
NonNullable
<
ResolvedMetadata
[
'twitter'
]
>
[
'creator'
]
type
MetadataTwitterCreator
=
NonNullable
<
Metadata
[
'twitter'
]
>
[
'creator'
]
type
ResolvedTwitterSiteId
=
NonNullable
<
ResolvedMetadata
[
'twitter'
]
>
[
'siteId'
]
type
MetadataTwitterSiteId
=
NonNullable
<
Metadata
[
'twitter'
]
>
[
'siteId'
]
type
ResolvedTwitterCreatorId
=
NonNullable
<
ResolvedMetadata
[
'twitter'
]
>
[
'creatorId'
]
type
MetadataTwitterCreatorId
=
NonNullable
<
Metadata
[
'twitter'
]
>
[
'creatorId'
]
type
ResolvedTwitterDescription
=
NonNullable
<
ResolvedMetadata
[
'twitter'
]
>
[
'description'
]
type
MetadataTwitterDescription
=
NonNullable
<
Metadata
[
'twitter'
]
>
[
'description'
]
type
ResolvedFacebookType
=
NonNullable
<
ResolvedMetadata
[
'facebook'
]
>
type
MetadataFacebookType
=
NonNullable
<
Metadata
[
'facebook'
]
>
type
ResolvedPinterestType
=
NonNullable
<
ResolvedMetadata
[
'pinterest'
]
>
type
MetadataPinterestType
=
NonNullable
<
Metadata
[
'pinterest'
]
>
describe
(
'Metadata and ResolvedMetadata type compatibility'
,
()
=>
{
describe
(
'top-level ResolvedMetadata'
,
()
=>
{
it
(
'should have ResolvedMetadata assignable to Metadata'
,
()
=>
{
// This tests spreading the entire resolved metadata: { ...parentMeta, title: 'Test' }
expectTypeOf
<
ResolvedMetadata
>
().
toMatchTypeOf
<
Metadata
>
()
})
})
describe
(
'openGraph property types'
,
()
=>
{
it
(
'should have ResolvedOpenGraph.url assignable to Metadata.openGraph.url'
,
()
=>
{
expectTypeOf
<
ResolvedOpenGraphUrl
>
().
toMatchTypeOf
<
MetadataOpenGraphUrl
>
()
})
})
describe
(
'twitter property types'
,
()
=>
{
it
(
'should have ResolvedTwitter.site assignable to Metadata.twitter.site'
,
()
=>
{
expectTypeOf
<
ResolvedTwitterSite
>
().
toMatchTypeOf
<
MetadataTwitterSite
>
()
})
it
(
'should have ResolvedTwitter.siteId assignable to Metadata.twitter.siteId'
,
()
=>
{
expectTypeOf
<
ResolvedTwitterSiteId
>
().
toMatchTypeOf
<
MetadataTwitterSiteId
>
()
})
it
(
'should have ResolvedTwitter.creator assignable to Metadata.twitter.creator'
,
()
=>
{
expectTypeOf
<
ResolvedTwitterCreator
>
().
toMatchTypeOf
<
MetadataTwitterCreator
>
()
})
it
(
'should have ResolvedTwitter.creatorId assignable to Metadata.twitter.creatorId'
,
()
=>
{
expectTypeOf
<
ResolvedTwitterCreatorId
>
().
toMatchTypeOf
<
MetadataTwitterCreatorId
>
()
})
it
(
'should have ResolvedTwitter.description assignable to Metadata.twitter.description'
,
()
=>
{
expectTypeOf
<
ResolvedTwitterDescription
>
().
toMatchTypeOf
<
MetadataTwitterDescription
>
()
})
})
describe
(
'facebook property types'
,
()
=>
{
it
(
'should have ResolvedFacebook assignable to Metadata.facebook'
,
()
=>
{
expectTypeOf
<
ResolvedFacebookType
>
().
toMatchTypeOf
<
MetadataFacebookType
>
()
})
})
describe
(
'pinterest property types'
,
()
=>
{
it
(
'should have ResolvedPinterest assignable to Metadata.pinterest'
,
()
=>
{
expectTypeOf
<
ResolvedPinterestType
>
().
toMatchTypeOf
<
MetadataPinterestType
>
()
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment