From f8039a9b4f0f532e1a8f121c0b6d95d4a78abe56 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Wed, 17 Jul 2024 18:14:51 +0200 Subject: [PATCH] Ensure thrown errors that are handled by React are associated with the original component not Next.js error boundaries --- packages/next/src/client/components/not-found-boundary.tsx | 5 +++-- packages/next/src/client/components/redirect-boundary.tsx | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/next/src/client/components/not-found-boundary.tsx b/packages/next/src/client/components/not-found-boundary.tsx index bfc40062fd2bfa..db44faa016fdfd 100644 --- a/packages/next/src/client/components/not-found-boundary.tsx +++ b/packages/next/src/client/components/not-found-boundary.tsx @@ -66,8 +66,9 @@ class NotFoundErrorBoundary extends React.Component< notFoundTriggered: true, } } - // Re-throw if error is not for 404 - throw error + return { + notFoundTriggered: false, + } } static getDerivedStateFromProps( diff --git a/packages/next/src/client/components/redirect-boundary.tsx b/packages/next/src/client/components/redirect-boundary.tsx index c4530614895acf..a9a1f505885fb1 100644 --- a/packages/next/src/client/components/redirect-boundary.tsx +++ b/packages/next/src/client/components/redirect-boundary.tsx @@ -54,8 +54,10 @@ export class RedirectErrorBoundary extends React.Component< const redirectType = getRedirectTypeFromError(error) return { redirect: url, redirectType } } - // Re-throw if error is not for redirect - throw error + return { + redirect: null, + redirectType: null, + } } // Explicit type is needed to avoid the generated `.d.ts` having a wide return type that could be specific the the `@types/react` version.