Why do we export the metadata object instead of just defining it inside the component?
Next.js needs the metadata object exported at the module level to detect it during build and inject it into the HTML head, as shown in execution_table step 2.
Does the metadata object affect the page content inside the <main> tag?
No, metadata is separate from page content. The metadata only affects the HTML head, while the <main> tag content is rendered as usual (see execution_table step 6).
What happens if we forget to include a description in the metadata?
The page will have no meta description tag, which can hurt SEO and social sharing previews. The metadata object must include description for best results (see execution_table step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the metadata object state after step 2?
Check the 'Metadata Object State' column at step 2 in the execution_table.
At which step does Next.js inject the metadata into the HTML <head>?
AStep 4
BStep 3
CStep 5
DStep 6
💡 Hint
Look for the step where 'Next.js adds and tags' in the 'Next.js Behavior' column.
If we remove the description from metadata, what changes in the execution table?
AThe page content will not render
BThe <meta name="description"> tag will be missing in the HTML
CThe <title> tag will be missing
DNext.js will throw an error
💡 Hint
Refer to step 4's 'Result in HTML' column showing meta tags injected.
Concept Snapshot
Next.js Metadata API for SEO:
- Export a metadata object from your page/component
- Include title, description, and other SEO tags
- Next.js injects these into the HTML <head> automatically
- Improves SEO and social sharing previews
- Metadata is separate from page content
Full Transcript
This visual execution trace shows how Next.js uses the Metadata API for SEO. First, you define a metadata object with properties like title and description. Then you export this object from your page module. Next.js detects this export during build time and prepares to inject it into the HTML head. When rendering the page, Next.js adds the appropriate <title> and <meta> tags inside the head section. Browsers and search engines then use this metadata to improve SEO and social sharing previews. The page content inside the main tag renders separately and is unaffected by metadata. This process ensures your page is SEO-friendly with minimal code.