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
f0a6103d
Unverified
Commit
f0a6103d
authored
Sep 10, 2025
by
Jiachi Liu
Committed by
GitHub
Sep 10, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[metadata] change the metadata routes params to promises (#83560)
parent
8bc22180
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
64 additions
and
34 deletions
+64
-34
route.rs
crates/next-core/src/next_app/metadata/route.rs
+20
-9
next-metadata-route-loader.ts
...t/src/build/webpack/loaders/next-metadata-route-loader.ts
+20
-9
icon.jsx
test/e2e/app-dir/logging/app/dynamic/[slug]/icon.jsx
+4
-2
icon.tsx
...tadata-dynamic-routes/app/(group)/dynamic/[size]/icon.tsx
+4
-2
opengraph-image.tsx
...mic-routes/app/(group)/dynamic/[size]/opengraph-image.tsx
+3
-2
icon.tsx
test/e2e/app-dir/metadata-dynamic-routes/app/gsp/icon.tsx
+4
-2
sitemap.ts
test/e2e/app-dir/metadata-dynamic-routes/app/gsp/sitemap.ts
+4
-3
sitemap.ts
.../use-cache-metadata-route-handler/app/products/sitemap.ts
+5
-5
No files found.
crates/next-core/src/next_app/metadata/route.rs
View file @
f0a6103d
...
...
@@ -288,10 +288,12 @@ async fn dynamic_sitemap_route_with_generate_source(
}}
export async function GET(_, ctx) {{
const
{{ __metadata_id__: id, ...params }} = await ctx.params || {{}}
const
hasXmlExtension = id ? id.endsWith('.xml') : false
const
paramsPromise = ctx.params
const
idPromise = paramsPromise.then(params => params?.__metadata_id__)
if (process.env.NODE_ENV !== 'production') {{
const id = await idPromise
const hasXmlExtension = id ? id.endsWith('.xml') : false
const sitemaps = await generateSitemaps()
let foundId
for (const item of sitemaps) {{
...
...
@@ -310,8 +312,11 @@ async fn dynamic_sitemap_route_with_generate_source(
}}
}}
const targetId = id && hasXmlExtension ? id.slice(0, -4) : undefined
const data = await handler({{ id: targetId }})
const targetIdPromise = idPromise.then(id => {{
const hasXmlExtension = id ? id.endsWith('.xml') : false
return id && hasXmlExtension ? id.slice(0, -4) : undefined
}})
const data = await handler({{ id: targetIdPromise }})
const content = resolveRouteData(data, fileType)
return new NextResponse(content, {{
...
...
@@ -433,11 +438,17 @@ async fn dynamic_image_route_with_metadata_source(
}}
export async function GET(_, ctx) {{
const params = await ctx.params
const {{ __metadata_id__, ...rest }} = params || {{}}
const restParams = params ? rest : undefined
const paramsPromise = ctx.params
const idPromise = paramsPromise.then(params => params?.__metadata_id__)
const restParamsPromise = paramsPromise.then(params => {{
if (!params) return undefined
const {{ __metadata_id__, ...rest }} = params
return rest
}})
if (process.env.NODE_ENV !== 'production') {{
const restParams = await restParamsPromise
const __metadata_id__ = await idPromise
const imageMetadata = await generateImageMetadata({{ params: restParams }})
const id = imageMetadata.find((item) => {{
if (item?.id == null) {{
...
...
@@ -454,7 +465,7 @@ async fn dynamic_image_route_with_metadata_source(
}}
}}
return handler({{ params: restParams
, id: __metadata_id__
}})
return handler({{ params: restParams
Promise, id: idPromise
}})
}}
export * from {resource_path}
...
...
@@ -502,7 +513,7 @@ async fn dynamic_image_route_without_metadata_source(
}}
export async function GET(_, ctx) {{
return handler({{ params:
await
ctx.params }})
return handler({{ params: ctx.params }})
}}
export * from {resource_path}
...
...
packages/next/src/build/webpack/loaders/next-metadata-route-loader.ts
View file @
f0a6103d
...
...
@@ -169,12 +169,18 @@ ${errorOnBadHandler(resourcePath)}
${
await
createReExportsCode
(
resourcePath
,
loaderContext
)}
export async function GET(_, ctx) {
const params = await ctx.params
const { __metadata_id__, ...rest } = params || {}
const restParams = params ? rest : undefined
const paramsPromise = ctx.params
const idPromise = paramsPromise.then(params => params?.__metadata_id__)
const restParamsPromise = paramsPromise.then(params => {
if (!params) return undefined
const { __metadata_id__, ...rest } = params
return rest
})
${
/* we need a dev assertion for id since dynamicParams=false won't work well in dev */
''
}
if (process.env.NODE_ENV !== 'production') {
const restParams = await restParamsPromise
const __metadata_id__ = await idPromise
const imageMetadata = await generateImageMetadata({ params: restParams })
const id = imageMetadata.find((item) => {
if (item?.id == null) {
...
...
@@ -191,7 +197,7 @@ export async function GET(_, ctx) {
}
}
return handler({ params: restParams
, id: __metadata_id__
})
return handler({ params: restParams
Promise, id: idPromise
})
}
export const dynamicParams = false
...
...
@@ -223,7 +229,7 @@ ${errorOnBadHandler(resourcePath)}
${
await
createReExportsCode
(
resourcePath
,
loaderContext
)}
export async function GET(_, ctx) {
return handler({ params:
await
ctx.params })
return handler({ params: ctx.params })
}
`
}
...
...
@@ -294,10 +300,12 @@ ${errorOnBadHandler(resourcePath)}
${
await
createReExportsCode
(
resourcePath
,
loaderContext
)}
export async function GET(_, ctx) {
const
{ __metadata_id__: id, ...params } = await ctx.params || {}
const
hasXmlExtension = id ? id.endsWith('.xml') : false
const
paramsPromise = ctx.params
const
idPromise = paramsPromise.then(params => params?.__metadata_id__)
if (process.env.NODE_ENV !== 'production') {
const id = await idPromise
const hasXmlExtension = id ? id.endsWith('.xml') : false
const sitemaps = await generateSitemaps()
let foundId
for (const item of sitemaps) {
...
...
@@ -317,8 +325,11 @@ export async function GET(_, ctx) {
}
}
const targetId = id && hasXmlExtension ? id.slice(0, -4) : undefined
const data = await handler({ id: targetId })
const targetIdPromise = idPromise.then(id => {
const hasXmlExtension = id ? id.endsWith('.xml') : false
return id && hasXmlExtension ? id.slice(0, -4) : undefined
})
const data = await handler({ id: targetIdPromise })
const content = resolveRouteData(data, fileType)
return new NextResponse(content, {
...
...
test/e2e/app-dir/logging/app/dynamic/[slug]/icon.jsx
View file @
f0a6103d
import
{
ImageResponse
}
from
'next/og'
export
default
function
icon
({
params
,
id
})
{
export
default
async
function
icon
({
params
,
id
})
{
const
{
size
}
=
await
params
const
iconId
=
await
id
return
new
ImageResponse
(
(
<
div
...
...
@@ -15,7 +17,7 @@ export default function icon({ params, id }) {
color
:
'#fafafa'
,
}
}
>
Apple
{
params
.
size
}
{
i
d
}
Apple
{
size
}
{
iconI
d
}
</
div
>
)
)
...
...
test/e2e/app-dir/metadata-dynamic-routes/app/(group)/dynamic/[size]/icon.tsx
View file @
f0a6103d
...
...
@@ -15,7 +15,9 @@ export async function generateImageMetadata({ params }) {
]
}
export
default
function
icon
({
params
,
id
})
{
export
default
async
function
icon
({
params
,
id
})
{
const
{
size
}
=
await
params
const
iconId
=
await
id
return
new
ImageResponse
(
(
<
div
...
...
@@ -30,7 +32,7 @@ export default function icon({ params, id }) {
color
:
'#000'
,
}
}
>
Icon
{
params
.
size
}
{
i
d
}
Icon
{
size
}
{
iconI
d
}
</
div
>
)
)
...
...
test/e2e/app-dir/metadata-dynamic-routes/app/(group)/dynamic/[size]/opengraph-image.tsx
View file @
f0a6103d
...
...
@@ -2,8 +2,9 @@ import { ImageResponse } from 'next/og'
export
const
alt
=
'Open Graph'
export
default
function
og
({
params
})
{
const
big
=
params
.
size
===
'big'
export
default
async
function
og
({
params
})
{
const
{
size
}
=
await
params
const
big
=
size
===
'big'
const
background
=
big
?
'orange'
:
'#000'
return
new
ImageResponse
(
(
...
...
test/e2e/app-dir/metadata-dynamic-routes/app/gsp/icon.tsx
View file @
f0a6103d
...
...
@@ -15,7 +15,9 @@ export async function generateImageMetadata({ params }) {
]
}
export
default
function
icon
({
params
,
id
})
{
export
default
async
function
icon
({
params
,
id
})
{
const
{
size
}
=
await
params
const
iconId
=
await
id
return
new
ImageResponse
(
(
<
div
...
...
@@ -30,7 +32,7 @@ export default function icon({ params, id }) {
color
:
'#000'
,
}
}
>
Icon
{
params
.
size
}
{
i
d
}
Icon
{
size
}
{
iconI
d
}
</
div
>
)
)
...
...
test/e2e/app-dir/metadata-dynamic-routes/app/gsp/sitemap.ts
View file @
f0a6103d
...
...
@@ -9,14 +9,15 @@ export async function generateSitemaps() {
]
}
export
default
function
sitemap
({
id
}):
MetadataRoute
.
Sitemap
{
export
default
async
function
sitemap
({
id
}):
Promise
<
MetadataRoute
.
Sitemap
>
{
const
sitemapId
=
await
id
return
[
{
url
:
`https://example.com/dynamic/
${
i
d
}
`
,
url
:
`https://example.com/dynamic/
${
sitemapI
d
}
`
,
lastModified
:
'2021-01-01'
,
},
{
url
:
`https://example.com/dynamic/
${
i
d
}
/about`
,
url
:
`https://example.com/dynamic/
${
sitemapI
d
}
/about`
,
lastModified
:
'2021-01-01'
,
},
]
...
...
test/e2e/app-dir/use-cache-metadata-route-handler/app/products/sitemap.ts
View file @
f0a6103d
import
type
{
MetadataRoute
}
from
'next'
import
{
getSentinelValue
}
from
'../sentinel'
import
{
setTimeout
}
from
'timers/promises'
export
async
function
generateSitemaps
()
{
return
[{
id
:
0
},
{
id
:
1
}]
...
...
@@ -9,12 +8,13 @@ export async function generateSitemaps() {
export
default
async
function
sitemap
({
id
,
}:
{
id
:
number
id
:
Promise
<
number
>
}):
Promise
<
MetadataRoute
.
Sitemap
>
{
'use cache'
// Simulate I/O
await
setTimeout
(
100
)
const
resolvedId
=
await
id
return
[{
url
:
`https://acme.com/
${
id
}
?sentinel=
${
getSentinelValue
()}
`
}]
return
[
{
url
:
`https://acme.com/
${
resolvedId
}
?sentinel=
${
getSentinelValue
()}
`
},
]
}
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