2024-01-17 12:33:45 +01:00
---
2024-01-19 01:09:11 +01:00
title: Missing Suspense boundary with useSearchParams
2024-01-17 12:33:45 +01:00
---
#### Why This Error Occurred
2024-01-19 00:12:50 +01:00
Reading search parameters through `useSearchParams()` without a Suspense boundary will opt the entire page into client-side rendering. This could cause your page to be blank until the client-side JavaScript has loaded.
2024-01-17 12:33:45 +01:00
#### Possible Ways to Fix It
2024-01-19 00:12:50 +01:00
Ensure that calls to `useSearchParams()` are wrapped in a Suspense boundary.
2024-01-17 12:33:45 +01:00
2024-01-19 01:09:11 +01:00
```tsx filename="app/search.tsx" switcher
'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>
)
}
```
```jsx filename="app/search.js" switcher
2024-01-19 00:12:50 +01:00
'use client'
import { useSearchParams } from 'next/navigation'
2024-01-19 00:48:24 +01:00
import { Suspense } from 'react'
2024-01-19 00:12:50 +01:00
2024-01-19 00:48:24 +01:00
function Search() {
2024-01-19 00:12:50 +01:00
const searchParams = useSearchParams()
2024-01-19 00:48:24 +01:00
return <input placeholder="Search..." />
}
export function Searchbar() {
return (
// You could have a loading skeleton as the `fallback` too
<Suspense>
<Search />
</Suspense>
)
2024-01-19 00:12:50 +01:00
}
```
This will ensure the page does not de-opt to client-side rendering.
#### Disabling
2024-05-13 23:36:24 +02:00
> Note: This is only available with Next.js version 14.x. If you're in versions above 15 please fix it with the approach above.
2024-01-19 00:12:50 +01:00
We don't recommend disabling this rule. However, if you need to, you can disable it by setting the `missingSuspenseWithCSRBailout` option to `false` in your `next.config.js`:
```js filename="next.config.js"
module.exports = {
experimental: {
missingSuspenseWithCSRBailout: false,
},
}
```
This configuration option will be removed in a future major version.
2024-01-18 21:11:22 +01:00
2024-01-17 12:33:45 +01:00
### Useful Links
- [`useSearchParams`](https://nextjs.org/docs/app/api-reference/functions/use-search-params)