What Error Boundaries DON'T Catch: Server-Side Rendering
You'll learn: Why error boundaries are invisible during server-side rendering and what that means for full-stack React apps.
The Client-Only Safety Net
Error boundaries are React components that catch errors during rendering — but here's the critical limitation: they only work in the browser during client-side rendering. When your React app renders on the server (SSR), error boundaries don't activate at all.
Think of an error boundary like an airbag in a car. It's designed to protect you during a crash, but only while you're driving. If the car is being assembled in the factory (server-side rendering), the airbag isn't installed yet — any problems during assembly require different safety measures.
Why This Happens
Server-side rendering produces HTML strings that get sent to the browser. There's no interactive component tree yet, no React lifecycle running in the browser, and no error boundary sitting in memory ready to catch problems. The error boundary code exists in your component tree, but it's just markup at this stage.
If a component throws an error during SSR, it crashes the server render process entirely. The error bubbles up to your server framework (Next.js, Remix, Express, etc.), not to your error boundary component.
What This Means for You
You need two separate error handling strategies:
- Server-side: Catch errors in your server rendering logic with try-catch blocks or your framework's error handling
- Client-side: Use error boundaries for runtime errors after hydration
Key Takeaway: Error boundaries only protect client-side rendering; SSR errors must be caught with server-level error handling before the HTML ever reaches the browser.