Category: Next.js, React and TypeScript

Next.js: useSearchParams corrupts static 404 error page

Read this guide in Polish

During the next build there is a message about the missing Suspense border on / not-found, although the home page works. Hook reading a query string can be rendered by a common layout, even if it is not in the error page file itself.

How to determine the source of the error

View layout.tsx and all shared header or menu items using useSearchParams.

Start the production build and read the full track to find the component that shuts down static rendering.

What to do step by step

1. Separate the client component with the hook and surround it with Suspense as close to where to use, leaving the rest of the page rendered on the server.

2 . If the page is really to be dynamic, choose consciously dynamic rendering instead of artificially shutting down build rules.

How to check the score

The Build ends without an error / not-found, and support 404 and search in the menu work after overload.

What to do

Do not remove the entire routing mechanism or hide the problem by turning off the lynting.