Performance: Page.tsx as route definition
MEDIUM IMPACT
This affects the initial page load speed and how quickly the main content appears by defining routes as React Server Components in Next.js.
export default async function Page() { const res = await fetch('https://example.com/api/data'); const data = await res.json(); return <div>{data.content}</div>; }
import React from 'react'; export default function Page() { const [data, setData] = React.useState(null); React.useEffect(() => { fetch('/api/data').then(res => res.json()).then(setData); }, []); if (!data) return <p>Loading...</p>; return <div>{data.content}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side data fetching in Page.tsx | Many (due to hydration and updates) | Multiple reflows during loading | High paint cost due to delayed content | [X] Bad |
| Server-side async Page.tsx route | Minimal (static HTML) | Single reflow on initial paint | Low paint cost with immediate content | [OK] Good |