Download next.js/errors/deopted-into-client-rendering.mdx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/errors/deopted-into-client-rendering.mdx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/errors/deopted-into-client-rendering.mdx
-
curl -L -o deopted-into-client-rendering.mdx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/errors/deopted-into-client-rendering.mdx
2.21 kB
| --- | |
| title: Entire page deopted into client-side rendering | |
| --- | |
| ## Why This Error Occurred | |
| During static rendering, the entire page was deopted into client-side rendering by `useSearchParams` as there was no [Suspense boundary](/docs/app/api-reference/functions/use-search-params#static-rendering) that caught it. | |
| If a route is statically rendered, calling `useSearchParams()` will cause the tree up to the closest [Suspense boundary](/docs/app/api-reference/functions/use-search-params#static-rendering) to be client-side rendered. | |
| This allows a part of the page to be statically rendered while the dynamic part that uses `searchParams` can be client-side rendered. | |
| ## Possible Ways to Fix It | |
| You can reduce the portion of the route that is client-side rendered by wrapping the component that uses useSearchParams in a Suspense boundary. | |
| For example if `app/dashboard/search-bar.tsx` uses `useSearchParams` wrap the component in a [Suspense boundary](/docs/app/api-reference/functions/use-search-params#static-rendering) as shown in `app/dashboard/page.tsx`. | |
| ```tsx filename="app/dashboard/search-bar.tsx" | |
| 'use client' | |
| import { useSearchParams } from 'next/navigation' | |
| export default function SearchBar() { | |
| const searchParams = useSearchParams() | |
| const search = searchParams.get('search') | |
| // This will not be logged on the server when using static rendering | |
| console.log(search) | |
| return <>Search: {search}</> | |
| } | |
| ``` | |
| ```tsx filename="app/dashboard/page.tsx" | |
| import { Suspense } from 'react' | |
| import SearchBar from './search-bar' | |
| // This component passed as fallback to the Suspense boundary | |
| // will be rendered in place of the search bar in the initial HTML. | |
| // When the value is available during React hydration the fallback | |
| // will be replaced with the `<SearchBar>` component. | |
| function SearchBarFallback() { | |
| return <>placeholder</> | |
| } | |
| export default function Page() { | |
| return ( | |
| <> | |
| <nav> | |
| <Suspense fallback={<SearchBarFallback />}> | |
| <SearchBar /> | |
| </Suspense> | |
| </nav> | |
| <h1>Dashboard</h1> | |
| </> | |
| ) | |
| } | |
| ``` | |
| ## Useful Links | |
| - [`useSearchParams` static rendering documentation](/docs/app/api-reference/functions/use-search-params#static-rendering) | |