Common Next.js errorsuseSearchParams() should be wrapped in a suspense boundary
useSearchParams() should be wrapped in a suspense boundary at page "/search" stops next build. A Client Component reads the URL's query string on a page Next.js wants to prerender, and the query string is only known when someone visits.
Why it only shows up when you build
In development every page renders on demand, so useSearchParams has a real URL and nothing complains. The production build prerenders static pages ahead of time, where there is no URL yet.
How to fix it
Move the part that reads the query string into its own component and wrap it in Suspense. The rest of the page still prerenders; only that part waits for the browser.
app/search/search-box.tsx 'use client'
import { Suspense } from 'react'
import { useSearchParams } from 'next/navigation'
function Query() {
const q = useSearchParams().get('q') ?? ''
return <input defaultValue={q} placeholder="Search" />
}
export function SearchBox() {
return (
<Suspense fallback={<input placeholder="Search" disabled />}>
<Query />
</Suspense>
)
}
If the page is a Server Component, you can also read the searchParams prop there and pass the value down instead of using the hook.