My colleague and I have nearly finished a large project together. We migrated our application from a Laravel/React stack using Inertia.js to a headless architecture with Next.js (App Router) and Laravel as the backend.
Yesterday, we tried to set up a testing environment and attempted to build the project. During development, everything worked fine locally — we never encountered any major issues. But now, trying to build the project feels like opening a can of endless errors.
The project structure looks like this:
app/
- posts/
page.tsx <--- Entire frontend logic for this route
components/
table.tsx
dropdown.tsx
...etc.
The main issue: we made everything a client component.
I spent the whole day fixing one issue after another — things like "document is not defined", but once I fix one error, the next one appears. Sometimes, even a page that had no errors before suddenly breaks again.
The two most common errors we're facing:
"document is not defined"
"useSearchParams() should be wrapped in a suspense boundary at page..."
Our question:
Is there a solid tutorial or guide that explains how to properly split pages and components between server and client components in Next.js?
At this point, we’re really desperate for anything that could help us move forward.