Skip to content

Next.js build errorNext.js: “useSearchParams() should be wrapped in a suspense boundary”

The app runs in development, then next build, or the deploy on Vercel, fails with useSearchParams() should be wrapped in a suspense boundary. A component that reads the URL’s query string is on a page Next.js wants to build ahead of time. Here are the fixes from Next.js’s own error page, or hand it over at a fixed price.

Short answer

Move the code that calls useSearchParams() into a small Client Component and wrap it in <Suspense>. That keeps the rest of the page static. If the whole route should render on each request instead, call connection() in the Server Component page. To find the component, run next build --debug-prerender.

Why the build fails, and the fix

  1. 01

    A component reads useSearchParams() with no Suspense around it

    “Reading search parameters through useSearchParams() without a Suspense boundary will opt the entire page into client-side rendering.” Next.js, Missing Suspense boundary with useSearchParams

    Without a Suspense boundary, reading the query string would push the whole page to render in the browser, so the build stops. Wrap the smallest part that needs it, as in Next.js’s example:

    'use client'
    
    import { useSearchParams } from 'next/navigation'
    import { Suspense } from 'react'
    
    function Search() {
      const searchParams = useSearchParams()
    
      return <input placeholder="Search..." />
    }
    
    export function Searchbar() {
      return (
        // You could have a loading skeleton as the `fallback` too
        <Suspense>
          <Search />
        </Suspense>
      )
    }
  2. 02

    The page should render on every request

    “To make the route dynamically rendered, use the connection function in a Server Component (e.g. the Page or a wrapping Layout).” Next.js, Missing Suspense boundary with useSearchParams

    If the page depends on the request anyway, make the route dynamic. Next.js says to call connection() in a Server Component page or layout. Setting dynamic in a Client Component page has no effect. On a Next.js version from before connection() existed, Next.js’s docs use export const dynamic = 'force-dynamic' in a Server Component page.tsx or layout.tsx instead.

    import { connection } from 'next/server'
    
    export default async function Page() {
      await connection()
      return <div>...</div>
    }
  3. 03

    The whole page became a Client Component

    “Consider making the Page a Server Component again and isolating Client-only code (that uses useSearchParams) into child Client Components.” Next.js, Missing Suspense boundary with useSearchParams

    A page.tsx that starts with 'use client' makes the whole page a Client Component. Next.js suggests making it a Server Component again and keeping the code that uses useSearchParams in child Client Components.

Checked against the vendor’s docs on : Next.js docs: Missing Suspense boundary with useSearchParams.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Next.js hydration error · Build failed on Netlify or Vercel

Questions

More on this error

Can I just turn the check off?

Only in Next.js 14, with the missingSuspenseWithCSRBailout option, and Next.js doesn’t recommend it. In later versions the fix is the Suspense boundary or a dynamic route.

Which component is causing it?

Next.js suggests running next build --debug-prerender, which gives unminified stack traces with source maps pointing at the component and route.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; we reply by email, usually within one business day.