Performance: Root layout (required)
The root layout affects the initial page load speed and visual stability by defining the main structure and shared UI elements that load on every page.
export default function RootLayout({ children }) { return ( <html lang="en"> <body> <Header /> {children} </body> </html> ) }
export default function RootLayout({ children }) { return ( <html lang="en"> <body> <Header /> <HeavyComponent /> {children} </body> </html> ) }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy components in root layout | High (many nodes) | Multiple reflows | High paint cost | [X] Bad |
| Minimal static root layout | Low (few nodes) | Single reflow | Low paint cost | [OK] Good |
layout.js or layout.tsx inside the app/ folder.app/layout.js matches the required name and location.app/layout.js, what will be rendered on every page?export default function RootLayout({ children }) {
return (
My Site Header
{children}
)
}html element with body containing header, children, and footer.{children} placeholder renders the page content inside the layout.app/layout.js? export default function RootLayout({ children }) {
return (
Site Header
{children}
)
}html element wrapping the entire page content.html tagdiv instead of html, which breaks Next.js layout rules.app/layout.js?export default function RootLayout({ children }) {
return (
My App
{children}
)
}<head> to add metadata and global styles.<head> for fonts and titlelink for fonts and a title inside <head> is the correct way to add global styles and metadata.Pass the test and this pattern moves unknown