Question presented to candidate: "How do you set the page title, description and social tags in the App Router, including values that depend on data from a database?"
What a strong answer should cover:
- Export a
metadataobject for static values, or an asyncgenerateMetadatafunction for values that depend on params or data. - Metadata is merged from the root layout down to the page; a title
templatein a layout wraps child titles. metadataBaseturns relative URLs (canonical, Open Graph images) into absolute ones; without it social image URLs fall back to localhost.- A fetch used in both
generateMetadataand the page is memoized, so it runs once. - Since Next.js 15.2, metadata from a slow
generateMetadatastreams after the page for browsers, but blocks for HTML-limited bots so they still see it in the head.
Clarifying questions expected:
- "Does the title depend on data?" β then generateMetadata, reusing the same data function as the page.
- "Where will links be shared?" β Open Graph and Twitter tags matter for social previews.
Code / implementation expected: Yes β a layout with a template and a page with generateMetadata.