Instructions for Next.js 16 Server Components
When working with Server Components in Next.js 16:
- •
Default Behavior: All components in
app/are Server Components unless marked with'use client'. - •
Async Components:
- •Make components async to fetch data:
export default async function Page() { const data = await fetch(...); return <div>{data}</div>; }.
- •Make components async to fetch data:
- •
Data Fetching:
- •Use
fetchwith caching options:{ cache: 'force-cache' }for static,{ next: { revalidate: 3600 } }for ISR. - •Handle errors with try-catch.
- •Use
- •
Props and Serialization:
- •Pass serializable props to Client Components (no functions or Dates).
- •Use
Suspensefor streaming:<Suspense fallback={<Loading/>}><AsyncComponent/></Suspense>.
- •
Integration with Client Components:
- •Server Components can import and render Client Components.
- •Avoid importing Client Components that use hooks into Server Components.
- •
Rendering Modes:
- •Static: Default for routes without dynamic data.
- •Dynamic: Triggered by
cookies(),headers(), or dynamic functions. - •Use
export const dynamic = 'force-static';to override.
- •
Best Practices:
- •Keep logic server-side for security (e.g., API keys).
- •Optimize fetches with deduping and caching.
- •Use React Server Components for better performance.
References
Use the shared references located at: ../_shared/reference.md