Interactive demo comparing error handling approaches in Next.js 16.2: react-error-boundary (before) vs the workaround (digest filtering + key reset) vs the built-in catchError API (after).
Next.js provides error.tsx for route-level error handling out of the box. But when you need more granular, component-level error boundaries within a page, you need a different approach.
A UserProfile server component cycles through success, a database error, and notFound(). Three tabs show how each approach handles component-level errors:
- Before —
react-error-boundarycatches all errors, including framework-internal ones likenotFound()andredirect().reset()only clears client state without re-fetching server component data. - Workaround — Wraps data fetching in try/catch to filter and rethrow Next.js internal errors by checking the
digestproperty. Uses an ErrorBoundarykeychange +router.refresh()insidestartTransitionto properly re-fetch server component data on retry. - After —
catchErroris framework-aware.retry()re-fetches server component data, andnotFound()/redirect()propagate correctly to the framework.
pnpm install
pnpm devOpen http://localhost:3000.