Files
stack/packages/mosaic/framework/skills/next-best-practices/suspense-boundaries.md
T
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

1.4 KiB

Suspense Boundaries

Client hooks that cause CSR bailout without Suspense boundaries.

useSearchParams

Always requires Suspense boundary in static routes. Without it, the entire page becomes client-side rendered.

// Bad: Entire page becomes CSR
'use client';

import { useSearchParams } from 'next/navigation';

export default function SearchBar() {
  const searchParams = useSearchParams();
  return <div>Query: {searchParams.get('q')}</div>;
}
// Good: Wrap in Suspense
import { Suspense } from 'react';
import SearchBar from './search-bar';

export default function Page() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <SearchBar />
    </Suspense>
  );
}

usePathname

Requires Suspense boundary when route has dynamic parameters.

// In dynamic route [slug]
// Bad: No Suspense
'use client';
import { usePathname } from 'next/navigation';

export function Breadcrumb() {
  const pathname = usePathname();
  return <nav>{pathname}</nav>;
}
// Good: Wrap in Suspense
<Suspense fallback={<BreadcrumbSkeleton />}>
  <Breadcrumb />
</Suspense>

If you use generateStaticParams, Suspense is optional.

Quick Reference

Hook Suspense Required
useSearchParams() Yes
usePathname() Yes (dynamic routes)
useParams() No
useRouter() No