Unverified Commit 089ca2c0 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

docs: update multi sitemap argumenmt type (#85701)

In v16, `id` argument in metadata routes becomes promise which requries
to to unwrap it first to access the value

Follow up of #84491

Closes #85632

---------
Co-authored-by: 's avatarJoseph Chamochumbi <joseph.chamochumbi@vercel.com>
parent a2938847
...@@ -338,6 +338,37 @@ export default async function Image({ params, id }) { ...@@ -338,6 +338,37 @@ export default async function Image({ params, id }) {
} }
``` ```
## Async `id` parameter for `sitemap` (Breaking change)
Previously, the `id` values returned from [`generateSitemaps`](/docs/app/api-reference/functions/generate-sitemaps) were passed directly to the `sitemap` generating function.
```js filename="app/product/sitemap.js"
export async function generateSitemaps() {
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
}
// Next.js 15 - synchronous id access
export default async function sitemap({ id }) {
const start = id * 50000 // id is a number
// ...
}
```
Starting with **Next.js 16**, the `sitemap` generating function now receives `id` as a promise.
```js filename="app/product/sitemap.js"
export async function generateSitemaps() {
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
}
// Next.js 16 - asynchronous id access
export default async function sitemap({ id }) {
const resolvedId = await id // id is now Promise<number>
const start = resolvedId * 50000
// ...
}
```
## React 19.2 ## React 19.2
The App Router in **Next.js 16** uses the latest React [Canary release](https://react.dev/blog/2023/05/03/react-canaries), which includes the newly released React 19.2 features and other features being incrementally stabilized. Highlights include: The App Router in **Next.js 16** uses the latest React [Canary release](https://react.dev/blog/2023/05/03/react-canaries), which includes the newly released React 19.2 features and other features being incrementally stabilized. Highlights include:
......
...@@ -349,11 +349,10 @@ export async function generateSitemaps() { ...@@ -349,11 +349,10 @@ export async function generateSitemaps() {
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }] return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
} }
export default async function sitemap({ export default async function sitemap(props: {
id, id: Promise<number>
}: {
id: number
}): Promise<MetadataRoute.Sitemap> { }): Promise<MetadataRoute.Sitemap> {
const id = await props.id
// Google's limit is 50,000 URLs per sitemap // Google's limit is 50,000 URLs per sitemap
const start = id * 50000 const start = id * 50000
const end = start + 50000 const end = start + 50000
...@@ -375,7 +374,8 @@ export async function generateSitemaps() { ...@@ -375,7 +374,8 @@ export async function generateSitemaps() {
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }] return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
} }
export default async function sitemap({ id }) { export default async function sitemap(props) {
const id = await props.id
// Google's limit is 50,000 URLs per sitemap // Google's limit is 50,000 URLs per sitemap
const start = id * 50000 const start = id * 50000
const end = start + 50000 const end = start + 50000
...@@ -420,6 +420,7 @@ type Sitemap = Array<{ ...@@ -420,6 +420,7 @@ type Sitemap = Array<{
| Version | Changes | | Version | Changes |
| ---------- | ------------------------------------------------------------ | | ---------- | ------------------------------------------------------------ |
| `v16.0.0` | `id` is now a promise that resolves to a number. |
| `v14.2.0` | Add localizations support. | | `v14.2.0` | Add localizations support. |
| `v13.4.14` | Add `changeFrequency` and `priority` attributes to sitemaps. | | `v13.4.14` | Add `changeFrequency` and `priority` attributes to sitemaps. |
| `v13.3.0` | `sitemap` introduced. | | `v13.3.0` | `sitemap` introduced. |
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