Next.js Discord

Discord Forum

Error: Cannot read properties of undefined (reading 'openGraph')

Answered
Dunker posted this in #help-forum
Open in Discord
Avatar
DunkerOP
Unable to fetch parent layout's metadata, any idea what could cause this issue?
export async function generateMetadata(props: {
    params: { tournament: string; seasonNo: number }
    parent: ResolvingMetadata
}): Promise<Metadata> {
    const { tournament, seasonNo } = props.params

    const tournamentData = await getTournamentData(tournament, seasonNo)
    const { tournamentName: name, seasonNo: season } = tournamentData

    const [_, imageUrl] = await getMatchesData(tournament, seasonNo)

    const title = `Matches | ${name} - Season ${season}`
    const description = 'Upcoming matches & results of ' + `${name}, Season ${season}`

    return {
        title: title,
        description: description,
        openGraph: {
            siteName: (await props.parent).openGraph?.siteName,
            title: title,
            images: imageUrl,
            description: description
        },
        twitter: {
            title: title,
            images: imageUrl,
            description: description
        }
    }
}


https://media.discordapp.net/attachments/663324452934778880/1163840526152372315/image.png?ex=654109f4&is=652e94f4&hm=e35d768f1433c11e8556014999fa8297f16bc977fe6ffedd4efe28ecee70b731&=&width=1140&height=513
Answered by Chinese Egret
parent is the second argument to generateMetadata, not in the object 🙂
View full answer

8 Replies

Avatar
Chinese Egret
parent is the second argument to generateMetadata, not in the object 🙂
Answer
Avatar
SupremeDeity
And how to use parent as well ^.
Its in that code example.
Avatar
DunkerOP
I feel stupid, did not realize i was putting it under props object.
thanks!
thank you very much
Avatar
SupremeDeity
Mark the answer 🙂