Fix guides · Cursor, Claude Code, v0, Bolt ·
Fix useSearchParams() should be wrapped in Suspense
useSearchParams() should be wrapped in a suspense boundary at page "/". Read more: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout
This Next.js build error means a Client Component calls useSearchParams() on a page that Next.js tries to pre-render as static HTML, and there is no <Suspense> boundary around it. Search params only exist in the browser, so Next.js refuses to build the page. The fix is to move the code that reads search params into its own small client component and wrap that component in <Suspense> with a fallback.
Common causes – and how to tell which one you have
1. Client component reads search params without Suspense
How to tell: The error names one page, and a component on that page (often a search bar, filter, pagination or login form) has 'use client' and calls useSearchParams(). It works in next dev but fails in next build.
Fix: Wrap the component that calls useSearchParams() in <Suspense fallback={...}> in the parent page or layout. Keep the boundary as small as possible so the rest of the page stays static.
2. The hook sits directly in page.tsx
How to tell: page.tsx itself starts with 'use client' and calls useSearchParams() at the top, so there is no parent to put Suspense in.
Fix: Move the search-param logic into a new client component (for example SearchFilters.tsx), make page.tsx render <Suspense><SearchFilters /></Suspense>, or read the searchParams prop in a Server Component page instead.
3. Shared component in a layout or header
How to tell: The error appears for many pages at once, or for "/404" or "/_not-found", because a navbar, analytics or toast component in the root layout uses useSearchParams().
Fix: Wrap that shared component in <Suspense> inside the layout. Do this once and every page that uses the layout builds again.
4. A library hook uses search params internally
How to tell: Your own code doesn't call useSearchParams(), but you use a hook or component from a library (auth, analytics, query-state helpers) that does.
Fix: Find the component that uses the library hook and wrap it in <Suspense>. Running next build --debug-prerender gives a more detailed trace that helps find it.
5. The page really should be dynamic
How to tell: The whole page depends on the query string (a search results page) and a static shell adds nothing.
Fix: Use the searchParams prop in a Server Component page (in recent Next.js versions it's a Promise, so await it) and pass values down as props. Then no client hook and no Suspense boundary is needed.
How to fix it
- Run npm run build (or check your host's build log) and note the page named in the error, for example "/search".
- Find the component on that page that calls useSearchParams(). If it's in page.tsx itself, move that code into a new file such as components/SearchFilters.tsx with 'use client' at the top.
- In the page (or layout) that renders it, import { Suspense } from 'react' and render <Suspense fallback={<div>Loading…</div>}><SearchFilters /></Suspense>.
- If the error lists many routes or "/404", look for useSearchParams() in components used by app/layout.tsx (navbar, analytics, toasts) and wrap those in Suspense too.
- Run npm run build again and repeat until it completes. If you can't find the component, run next build --debug-prerender for a more detailed trace.
- Open the page with a query string (for example ?q=test) in production and check the filters still read and update the URL.
Using Lovable, Bolt or v0?
In v0 or Bolt, tell the AI: "The production build fails with 'useSearchParams() should be wrapped in a suspense boundary'. Move the code that reads search params into its own client component and wrap it in <Suspense> with a small fallback in the page. Don't make the whole app dynamic." Then redeploy and check the build log on Vercel or your host shows the page as built.
Using Cursor, Claude Code or Windsurf?
Ask Cursor or Claude Code to search the project for every useSearchParams() call, list which page and layout renders each one, and wrap the smallest possible component in <Suspense>. Make it run npm run build afterwards and confirm the build finishes with no missing-suspense error for any route, including /404.
The “fix” to avoid
Agents often add export const dynamic = 'force-dynamic' to the page or root layout, or turn off static generation for the whole app. The build passes, but every page is now rendered on every request, which is slower and costs more. Some also remove the hook and read window.location in useEffect, which breaks client-side navigation updates. Add a Suspense boundary instead.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
My Next.js build fails with: "useSearchParams() should be wrapped in a suspense boundary at page \"/\"". Find every useSearchParams() call (including in components used by app/layout.tsx and in library hooks). For each page named in the error: move the code that reads search params into its own 'use client' component and render it inside <Suspense fallback={...}> in the parent, keeping the boundary as small as possible. If page.tsx is a Server Component and only needs the values, read the searchParams prop instead. Do not add export const dynamic = 'force-dynamic' and do not replace the hook with window.location. Run npm run build and confirm it completes with no missing-suspense error for any route, including /404. Then tell me which files you changed.
Questions people ask
Why does it work in npm run dev but fail in npm run build?
The dev server renders every page on request, so search params are always available. The production build pre-renders static pages ahead of time without a URL, so it needs a Suspense boundary to know which part to leave for the browser.
Does wrapping in Suspense make my page slower?
No. The rest of the page stays static and fast; only the small part inside the boundary waits for the browser. Forcing the whole page dynamic is the slower option.
What should the Suspense fallback be?
Something the same size as the real component, such as an empty search box or a skeleton, so the layout doesn't jump. null also works if the component is small.