Performance: Nested layouts
MEDIUM IMPACT
Nested layouts affect the initial page load speed and rendering performance by controlling how much UI is reused and how often components re-render.
export const metadata = { title: 'App' } export default function RootLayout({ children }) { return ( <html> <body> <header>Header</header> {children} <footer>Footer</footer> </body> </html> ) } // Nested layouts reuse RootLayout, only inner content changes on navigation
export default function Page() { return ( <html> <body> <header>Header</header> <main> <section>Content</section> </main> <footer>Footer</footer> </body> </html> ) } // Each page repeats full layout causing full re-render every navigation
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full layout repeated per page | High (full DOM tree rebuilt) | Multiple reflows per navigation | High paint cost due to full repaint | [X] Bad |
| Nested layouts with shared components | Low (only inner DOM changes) | Single reflow on content change | Lower paint cost, partial repaint | [OK] Good |