-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(react): Add children prop type to ErrorBoundary component #4966
Conversation
packages/react/src/errorboundary.tsx
Outdated
@@ -66,7 +66,7 @@ const INITIAL_STATE = { | |||
* Sentry React SDK ErrorBoundary caught an error invoking your application code. This | |||
* is expected behavior and NOT indicative of a bug with the Sentry React SDK. | |||
*/ | |||
class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> { | |||
class ErrorBoundary extends React.Component<React.PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cameronaziz, thank you so much for submitting this PR. We would like to fix this type error and release a patch.
Would you be willing to get rid of the React.PropsWithChildren
helper here and instead add a children?: React.ReactNode
prop to ErrorBoundaryProps
, just like one of the maintainers of react suggests here? If that's done we're good to go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1a575e6 without the | undefined
would be perfect imo.
That should be fine typewise. Seems weird that it's not building. Can you update the code? I'll take a look at the build output afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can, but that ends up making the children
within this block a never
.
sentry-javascript/packages/react/src/errorboundary.tsx
Lines 153 to 155 in cafec74
if (typeof children === 'function') { | |
return children(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Apparently @types/react@18
changed the ReactNode
type not to be callable anymore. I think up to v17 it had a constructor type of some sort. For me, when using the types from @type/react@18
neither children?: ReactNode
nor React.PropsWithChildren
works. I think it's best if we go with the changes from ea99673.
Sorry for flip-flopping around. Thank you very much for helping out 🙏
@cameronaziz I took the liberty of taking this over and merging. We'll include the changes in our next patch. Thank you for your contribution! |
To support React 18, which removed
children
as an optional prop for functional components, this addschildren
as an option prop for theErrorBoundary
component.Fixes #4904