/ blog/debugging-server-component-boundaries
blog / debugging-server-component-boundaries / overview.md

The Quickest Way to Debug Server Component Boundaries

How to trace exactly where your Next.js application switches from Server to Client.

In Next.js, it's easy to accidentally make a huge chunk of your app a Client Component by placing a "use client" directive too high in the tree.

The Debugging Trick: Add console.log("Rendering Component X") in the body of your components.

  • If it prints in your terminal, it rendered on the server.
  • If it prints in your browser console, it hydrated on the client.
  • If it prints in both, it's a Client Component that was SSR'd.

To ensure a component NEVER renders on the client, import the server-only package:

import 'server-only';

If any Client Component tries to import it, the build will hard fail.

Tags

nextjsdebugging
0
0