Performance: Nested routes and layouts
MEDIUM IMPACT
Nested routes and layouts impact initial page load speed and rendering performance by controlling how much UI is reused and how many components are rendered or re-rendered.
import { Outlet } from "@remix-run/react"; export default function RootLayout() { return ( <html> <body> <Header /> <Outlet /> <Footer /> </body> </html> ); } // Nested route file: routes/dashboard.jsx export default function Dashboard() { return <main>Dashboard content</main>; }
export default function App() {
return (
<div>
<Header />
{window.location.pathname === '/dashboard' && <Dashboard />}
{window.location.pathname === '/settings' && <Settings />}
<Footer />
</div>
);
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual conditional rendering of pages inside a single component | High - rebuilds many nodes | Multiple reflows per route change | High paint cost due to full layout repaint | [X] Bad |
| Nested routes with shared layouts and <Outlet> | Low - reuses layout nodes | Single reflow limited to changed content | Lower paint cost by partial updates | [OK] Good |