feat(react): Convert non-Error objects to Error instances in ErrorBoundary#1786
feat(react): Convert non-Error objects to Error instances in ErrorBoundary#1786
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
People can be co-author:
|
Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
Updated the implementation to follow Sentry's approach. Changed type signatures for
Updated the implementation to follow Sentry's approach. Changed type signatures for Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot rebase |
There was a problem hiding this comment.
Pull request overview
Updates @suspensive/react’s ErrorBoundary to normalize non-Error thrown values into real Error instances so fallback rendering and onError callbacks consistently receive an Error.
Changes:
- Added a
convertToErrorhelper and applied it ingetDerivedStateFromErrorandcomponentDidCatch. - Added tests covering conversion behavior for
null, strings, numbers, and objects (both for fallback props andonError). - Updated an example
tsconfig.tsbuildinfofile (TypeScript version metadata change).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/react/src/ErrorBoundary.tsx | Adds convertToError and normalizes error values passed through boundary lifecycles. |
| packages/react/src/ErrorBoundary.spec.tsx | Adds test coverage ensuring fallback/onError receive Error instances for non-Error throws. |
| examples/vite-react-18-suspense-prerender-siblings-problem/tsconfig.tsbuildinfo | Updates generated build-info metadata (TypeScript version). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| static getDerivedStateFromError(error: any): ErrorBoundaryState { | ||
| return { isError: true, error: convertToError(error) } | ||
| } |
There was a problem hiding this comment.
getDerivedStateFromError is using any with an eslint disable. Since the method body immediately normalizes via convertToError, you can keep the React-typed signature (error: Error) or use unknown to avoid any and retain type-safety without suppressing the lint rule.
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| componentDidCatch(error: any, info: ErrorInfo) { |
There was a problem hiding this comment.
componentDidCatch is also typed as any with a lint suppression. Consider using the standard React signature (error: Error) or unknown, and then normalize with convertToError, so callers of onError remain strongly typed and you can drop the eslint disable.
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| componentDidCatch(error: any, info: ErrorInfo) { | |
| componentDidCatch(error: unknown, info: ErrorInfo) { |
| @@ -1 +1 @@ | |||
| {"root":["./src/App.tsx","./src/main.tsx","./src/vite-env.d.ts","./vite.config.ts"],"version":"5.8.3"} No newline at end of file | |||
| {"root":["./src/App.tsx","./src/main.tsx","./src/vite-env.d.ts","./vite.config.ts"],"version":"5.9.2"} No newline at end of file | |||
There was a problem hiding this comment.
tsconfig.tsbuildinfo appears to be a generated build artifact, and this change is only updating the embedded TypeScript version (5.8.3 → 5.9.2) without any related source changes. It should typically be reverted/removed from the PR to avoid noisy diffs tied to local tooling versions.
| {"root":["./src/App.tsx","./src/main.tsx","./src/vite-env.d.ts","./vite.config.ts"],"version":"5.9.2"} | |
| {"root":["./src/App.tsx","./src/main.tsx","./src/vite-env.d.ts","./vite.config.ts"],"version":"5.8.3"} |
Rebased onto latest |
getDerivedStateFromErrorto convert non-Error objects to Error instancescomponentDidCatchto convert non-Error objects for onError callbackconvertToErrorhelper function for consistent conversion logicanytype for error parameters (following Sentry's approach)Original prompt
Fixes #1785
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.