---
title: "useSearchParams() should be wrapped in a suspense boundary"
description: "next build fails because a Client Component calls useSearchParams without Suspense. Learn why Next.js needs the boundary and the cleanest ways to fix it."
url: https://www.danny.engineering/answer/nextjs/usesearchparams-should-be-wrapped-in-a-suspense-boundary
author: Danny
published: 2026-12-01T00:00:00.000Z
updated: 2026-11-28T00:10:00.000Z
tags: ["Next.js"]
---

# useSearchParams() should be wrapped in a suspense boundary

## The short answer


A Client Component on a prerendered page calls `useSearchParams()`, and nothing above it is wrapped in `Suspense`. The search params are not known at build time, so Next.js needs a boundary to show a fallback in their place. Move the hook into a small component and wrap that component in `Suspense`.


```typescript
// app/search/page.tsx
import { Suspense } from 'react';
import { SearchBar } from './search-bar';

export default function Page() {
  return (
    <main>
      <h1>Search</h1>
      <Suspense fallback={<p>Loading search...</p>}>
        <SearchBar />
      </Suspense>
    </main>
  );
}
```


## Why it happens


During `next build`, Next.js tries to prerender every route it can into static HTML. A query string such as `?q=shoes` only exists when a real request arrives, so a component that reads it cannot be rendered at build time.


Without a `Suspense` boundary, Next.js has no smaller piece to skip. The only option would be to render the whole page in the browser, which means a blank page until the JavaScript loads. Rather than do that silently, the production build fails with an error such as `useSearchParams() should be wrapped in a suspense boundary at page "/search"`.


With a boundary in place, Next.js prerenders everything outside it and puts the fallback in the HTML. In the browser, the component inside renders with the real search params.


The error often does not show up in `next dev`, because development renders every request on demand and the hook does not suspend there. That is why it tends to appear for the first time in CI or on deploy.


If your app uses Cache Components (the `cacheComponents` option in Next.js 16), the rule is stricter: `useSearchParams()` always needs a `Suspense` boundary above it, because search params are request-time data.


## How to fix it


### Wrap the smallest component that reads the params


Keep the hook in a dedicated Client Component and wrap only that in `Suspense`, as in the short answer. The rest of the page stays static and fast.


```typescript
// app/search/search-bar.tsx
'use client';

import { useSearchParams } from 'next/navigation';

export function SearchBar() {
  const searchParams = useSearchParams();
  const query = searchParams.get('q') ?? '';

  return <input name="q" defaultValue={query} placeholder="Search" />;
}
```


Make the fallback the same size as the real component, so nothing jumps when it swaps in.


### Read searchParams on the server instead


If the page needs the query to fetch data anyway, read it in the page itself. The `searchParams` prop is a Promise, so await it. This makes the route render on each request, and no client hook is needed.


```typescript
// app/search/page.tsx
export default async function Page({
  searchParams,
}: {
  searchParams: Promise<{ q?: string }>;
}) {
  const { q = '' } = await searchParams;
  const results = await searchProducts(q);
  return <Results query={q} results={results} />;
}
```


You can also pass the `searchParams` Promise down to a Client Component and unwrap it there with React's `use()`. That component still needs a `Suspense` boundary above it.


### Make the route dynamic


If the whole page depends on the request, you can opt it out of prerendering. Without Cache Components, `export const dynamic = 'force-dynamic'` in the page or layout does this. Calling `await connection()` from `next/server` in a Server Component has the same effect. You lose the static shell, so prefer the first fix where you can.


## Common pitfalls

- **Wrapping the hook call instead of the component.** `Suspense` must sit above the component that calls the hook, in a parent. Wrapping JSX inside the same component does nothing.
- **Putting the boundary in the root layout.** It works, but the whole page becomes the fallback. Keep the boundary close to the component.
- **Assuming dev and prod behave the same.** Run `next build` locally before you push. `next build --debug-prerender` gives fuller stack traces to find the component.
- **Looking for a config flag to turn it off.** The old `missingSuspenseWithCSRBailout` option only existed in Next.js 14. Fix the boundary instead.
- **Other client hooks.** `usePathname()` can trigger the same error on dynamic routes, and the same fix applies.

## Related reading

- [Next.js: Missing Suspense boundary with useSearchParams](https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout)
- [Next.js: useSearchParams](https://nextjs.org/docs/app/api-reference/functions/use-search-params)
