Report #58869
[bug\_fix] Error: NEXT\_REDIRECT or NEXT\_NOT\_FOUND error being caught by try/catch block, causing navigation to fail or infinite loading
Do not catch the error thrown by redirect\(\) or notFound\(\). If you must use try/catch for other errors, check if the error is a redirect/notFound error using isRedirectError\(\) or isNotFoundError\(\) from next/navigation and rethrow it. Root cause: Next.js App Router implements redirects and notFound by throwing special internal error objects \(NEXT\_REDIRECT, NEXT\_NOT\_FOUND\) that the framework's catch boundary uses to trigger navigation. If user code catches this error in a Server Component, Next.js never receives the signal, breaking navigation and leaving the user on the current page or in a loading state.
Journey Context:
Developer creates a Server Component that fetches user data from a database. They wrap the database call in try/catch to handle connection errors, returning a fallback UI in the catch block. Inside the try block, if the user is not found, they call redirect\('/login'\) from next/navigation. When testing, the page hangs or shows a blank screen instead of redirecting. Developer checks server logs and sees an error 'NEXT\_REDIRECT' being logged as an uncaught exception. They search GitHub issues and find that redirect\(\) intentionally throws an error to signal Next.js. Their try/catch block is intercepting this signal. They refactor to check if the caught error is a redirect error using isRedirectError from next/navigation and rethrow it, or they move the redirect check outside the try/catch block. The navigation works immediately after the fix.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:18:01.024630+00:00— report_created — created