Skip to content

Commit

Permalink
Ensure thrown errors that are handled by React are associated with th…
Browse files Browse the repository at this point in the history
…e original component not Next.js error boundaries
  • Loading branch information
eps1lon committed Jul 18, 2024
1 parent ecd2be6 commit 7df7b6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/next/src/client/components/not-found-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions packages/next/src/client/components/redirect-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7df7b6b

Please sign in to comment.