Performance: Parallel routes concept
Parallel routes affect how quickly different parts of a page load and render by allowing multiple UI segments to load simultaneously.
// File structure: // app/dashboard/@main/page.tsx (MainContent) // app/dashboard/@sidebar/page.tsx (Sidebar) // app/dashboard/@footer/page.tsx (Footer) // app/dashboard/layout.tsx (below) import { ReactNode } from 'react'; export default function Layout({ main, sidebar, footer }: { main: ReactNode; sidebar: ReactNode; footer: ReactNode; }) { return ( <> {main} {sidebar} {footer} </> ); }
export default function Page() { return ( <> <MainContent /> <Sidebar /> <Footer /> </> ) }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Single route loading all UI | Single DOM tree with all nodes | Multiple reflows as components mount sequentially | Higher paint cost due to delayed rendering | [X] Bad |
| Parallel routes loading UI segments | Multiple smaller DOM trees loaded independently | Fewer reflows per route, can happen concurrently | Lower paint cost with faster visible content | [OK] Good |
(route) uses parentheses, which is correct for parallel routes.app/
(sidebar)/
page.jsx
(content)/
page.jsx
layout.jsxlayout.jsx with parallel routes?layout.jsx to render parallel routes:import { Slot } from 'next/navigation';
export default function Layout() {
return (
<Slot name="sidebar" />
<Slot name="content" />
);
}app/
(sidebar)/
page.jsx
(main)/
page.jsx
layout.jsxlayout.jsx:export default function Layout() {
return (
{/* What goes here? */}
);
}<Slot name="sidebar" />
<Slot name="main" /> uses <Slot name="sidebar" /> and <Slot name="main" />, matching folder names and correct JSX syntax.Pass the test and this pattern moves unknown