Report #13072
[bug\_fix] useSearchParams\(\) should be wrapped in a suspense boundary at page /path, or marked as a Client Component with 'use client'. Error during static generation: useSearchParams is not allowed in a Server Component.
Wrap the component consuming useSearchParams in a React Suspense boundary \(Loading... \}>\). Alternatively, if the entire page must be dynamic, export const dynamic = 'force-dynamic' to opt out of static generation.
Journey Context:
Developer uses useSearchParams from next/navigation inside a page component to read query parameters like ?search=term. During local development with next dev, the page loads perfectly because Next.js runs everything dynamically. When they run next build for production deployment, the build fails with an error stating useSearchParams cannot be used during static generation. Developer is confused because the hook is from Next.js itself. They try adding "use client" to the page, converting it to a Client Component, but this eliminates SSR benefits and may still require Suspense in newer Next.js versions. They search the error and find that useSearchParams triggers client-side navigation state reading, which requires the component to be treated as dynamic. The solution is to wrap the component in Suspense, which tells Next.js that this part of the tree depends on browser-only APIs and should be streamed/loaded client-side while the shell renders statically. This works because Suspense creates a boundary where the server can send a fallback, and the client hydrates the actual component with search params once mounted.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:43:27.552696+00:00— report_created — created