Challenge - 5 Problems
Metadata Master in Next.js Layouts
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
How does metadata in a Next.js layout affect the page?
Consider a Next.js app with a layout that defines metadata such as
title and description. What happens to the page's metadata when this layout is used?NextJS
export const metadata = { title: 'My Layout Title', description: 'Layout description' }; export default function Layout({ children }) { return <section>{children}</section>; }
Attempts:
2 left
💡 Hint
Think about how Next.js prioritizes metadata from layouts and pages.
✗ Incorrect
In Next.js, metadata defined in a layout applies to all pages using that layout unless a page defines its own metadata, which overrides the layout's metadata.
📝 Syntax
intermediate1:30remaining
Identify the correct way to export metadata in a Next.js layout
Which of the following code snippets correctly exports metadata in a Next.js layout file?
Attempts:
2 left
💡 Hint
Remember how to export constants in ES modules.
✗ Incorrect
The correct syntax to export a constant is using 'export const'. The other options have syntax errors.
❓ state_output
advanced2:00remaining
What is the final page title when nested layouts define metadata?
Given two nested layouts in Next.js, where the outer layout defines
title: 'Outer' and the inner layout defines title: 'Inner', what will be the page's title when rendered?NextJS
/* Outer layout */ export const metadata = { title: 'Outer' }; export default function OuterLayout({ children }) { return <div>{children}</div>; } /* Inner layout */ export const metadata = { title: 'Inner' }; export default function InnerLayout({ children }) { return <section>{children}</section>; }
Attempts:
2 left
💡 Hint
Think about which layout is closest to the page in the hierarchy.
✗ Incorrect
Next.js uses the metadata from the closest layout to the page, so the inner layout's title overrides the outer layout's title.
🔧 Debug
advanced2:30remaining
Why does this metadata not update on client navigation?
A developer defines metadata in a Next.js layout but notices that when navigating client-side, the metadata (like title) does not update. What is the likely cause?
NextJS
export const metadata = { title: 'Static Title' }; export default function Layout({ children }) { return <main>{children}</main>; }
Attempts:
2 left
💡 Hint
Consider how Next.js handles metadata updates during client navigation.
✗ Incorrect
Metadata defined in layouts is static and only applied once. For dynamic metadata updates on client navigation, pages need to define their own metadata or use dynamic metadata APIs.
🧠 Conceptual
expert3:00remaining
How does Next.js merge metadata from multiple nested layouts and pages?
In Next.js, when multiple nested layouts and a page define metadata objects with overlapping keys (e.g.,
title, description, icons), how does Next.js combine these metadata values for the final rendered page?Attempts:
2 left
💡 Hint
Think about how metadata like icons arrays and titles are handled in nested layouts.
✗ Incorrect
Next.js merges metadata objects deeply: scalar values like title or description are overridden by the closest layout or page, while arrays like icons are combined from all levels.