Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply Next.js best practices for RSC boundaries, async APIs, routing, metadata, and optimization.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
suspense-boundaries.md
1# Suspense Boundaries23Client hooks that cause CSR bailout without Suspense boundaries.45## useSearchParams67Always requires Suspense boundary in static routes. Without it, the entire page becomes client-side rendered.89```tsx10// Bad: Entire page becomes CSR11'use client'1213import { useSearchParams } from 'next/navigation'1415export default function SearchBar() {16const searchParams = useSearchParams()17return <div>Query: {searchParams.get('q')}</div>18}19```2021```tsx22// Good: Wrap in Suspense23import { Suspense } from 'react'24import SearchBar from './search-bar'2526export default function Page() {27return (28<Suspense fallback={<div>Loading...</div>}>29<SearchBar />30</Suspense>31)32}33```3435## usePathname3637Requires Suspense boundary when route has dynamic parameters.3839```tsx40// In dynamic route [slug]41// Bad: No Suspense42'use client'43import { usePathname } from 'next/navigation'4445export function Breadcrumb() {46const pathname = usePathname()47return <nav>{pathname}</nav>48}49```5051```tsx52// Good: Wrap in Suspense53<Suspense fallback={<BreadcrumbSkeleton />}>54<Breadcrumb />55</Suspense>56```5758If you use `generateStaticParams`, Suspense is optional.5960## Quick Reference6162| Hook | Suspense Required |63|------|-------------------|64| `useSearchParams()` | Yes |65| `usePathname()` | Yes (dynamic routes) |66| `useParams()` | No |67| `useRouter()` | No |68