Merge inherited social metadata
A product or article page needs to retain Open Graph images declared by layouts while adding its own image.
Next.js 16+ · Type Alias
ResolvingMetadata types the parent argument of generateMetadata. It provides a promise for metadata resolved by ancestor route segments, enabling a route to inspect and extend inherited metadata.
ResolvingMetadata is the type of the second argument passed to generateMetadata. It represents a promise for metadata already resolved by parent route segments, which lets a child route inspect and extend inherited values such as Open Graph images before returning its own Metadata object.
type ResolvingMetadata = Promise<Readonly<Metadata>>| Name | Type | Description |
|---|---|---|
parent | ResolvingMetadata | The second generateMetadata argument: a promise containing metadata resolved from parent route segments. |
A Promise<Metadata> from generateMetadata; ResolvingMetadata itself represents the promised parent metadata.
import type { Metadata, ResolvingMetadata } from 'next'
type Props = {
params: Promise<{ id: string }>
}
export async function generateMetadata(
{ params }: Props,
parent: ResolvingMetadata,
): Promise<Metadata> {
const { id } = await params
const previousImages = (await parent).openGraph?.images ?? []
return {
title: `Product ${id}`,
openGraph: {
images: ['/product.png', ...previousImages],
},
}
}Uses the resolved parent metadata to preserve existing Open Graph images while adding a route-specific image.
A product or article page needs to retain Open Graph images declared by layouts while adding its own image.
A nested route needs access to metadata established by parent layouts before returning route-specific fields.
A metadata generator must accurately type its second argument in TypeScript.
ResolvingMetadata is the type for generateMetadata's parent parameter. That parameter is a promise containing metadata resolved by parent route segments, allowing the current segment to inspect inherited values.
Follow-up: How would you preserve inherited Open Graph images? Await parent, read openGraph?.images with a fallback, and spread those images into the child route's returned openGraph metadata.
A generateMetadata function receives parent as ResolvingMetadata and returns a Promise<Metadata>. The child can await parent and return metadata fields for its own route segment.
Follow-up: Why is the parent value a promise? Metadata resolution follows the route tree, so parent metadata must be resolved before the child can consume it.
Metadata is evaluated from the root route segment toward the segment nearest the final page. A child can therefore extend metadata inherited from layouts instead of replacing useful values blindly.
Follow-up: What restriction applies to this API? Both static metadata and generateMetadata are supported only in Server Components.
MetadatagenerateMetadatametadataBaseopenGraph