Skip to content

Commit 6956097

Browse files
committed
Ensure thrown errors that are handled by React are associated with the original component not Next.js error boundaries
1 parent 669bd05 commit 6956097

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/next/src/client/components/not-found-boundary.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ class NotFoundErrorBoundary extends React.Component<
6666
notFoundTriggered: true,
6767
}
6868
}
69-
// Re-throw if error is not for 404
70-
throw error
69+
return {
70+
notFoundTriggered: false,
71+
}
7172
}
7273

7374
static getDerivedStateFromProps(

packages/next/src/client/components/redirect-boundary.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ export class RedirectErrorBoundary extends React.Component<
5454
const redirectType = getRedirectTypeFromError(error)
5555
return { redirect: url, redirectType }
5656
}
57-
// Re-throw if error is not for redirect
58-
throw error
57+
return {
58+
redirect: null,
59+
redirectType: null,
60+
}
5961
}
6062

6163
// Explicit type is needed to avoid the generated `.d.ts` having a wide return type that could be specific the the `@types/react` version.

0 commit comments

Comments
 (0)