-
-
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
feat(react)!: Update ErrorBoundary
componentStack
type
#14742
Conversation
size-limit report 📦
|
docs/migration/v8-to-v9.md
Outdated
@@ -70,6 +70,10 @@ Sentry.init({ | |||
|
|||
- When `skipOpenTelemetrySetup: true` is configured, `httpIntegration({ spans: false })` will be configured by default. This means that you no longer have to specify this yourself in this scenario. With this change, no spans are emitted once `skipOpenTelemetrySetup: true` is configured, without any further configuration being needed. | |||
|
|||
### `@sentry/react` | |||
|
|||
The `componentStack` field in the `ErrorBoundary` component is now typed as `string | undefined` instead of `string | null | undefined`. This more closely matches the actual behavior of React, which always returns a `string` whenever a component stack is available. `undefined` is only returned if no error has been caught by the error boundary. |
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.
m: Looking at the code, I don't see componentStack
being typed as string | undefined
but rather string | null
. Should we update the migration note accordingly?
The `componentStack` field in the `ErrorBoundary` component is now typed as `string | undefined` instead of `string | null | undefined`. This more closely matches the actual behavior of React, which always returns a `string` whenever a component stack is available. `undefined` is only returned if no error has been caught by the error boundary. | |
The `componentStack` field in the `ErrorBoundary` component is now typed as `string | null` instead of `string | null | undefined`. This more closely matches the actual behavior of React, which always returns a `string` whenever a component stack is available. `undefined` is only returned if no error has been caught by the error boundary. |
i might just also be missing something 😅 - in that case, feel free to disregard!
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.
Internally we keep the componentStack
as null
, but to the user it should always be defined. There is actually one scenario where things are now null
, I extended the changelog to talk about this.
packages/react/src/errorboundary.tsx
Outdated
/** Called on componentDidMount() */ | ||
onMount?: (() => void) | undefined; | ||
/** Called if resetError() is called from the fallback render props function */ | ||
onReset?: ((error: unknown, componentStack: string | null | undefined, eventId: string | null) => void) | undefined; | ||
onReset?: ((error: unknown, componentStack: string | null, eventId: string | null) => void) | undefined; |
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.
Can we remove null
here as well?
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.
Not exactly, I expanded the migration doc to talk about this.
4e80697
to
04f6178
Compare
sorry for the delay, refactored this a little more, ready for another round! |
resolves #14310
supercedes #14327 (I have left @kunal-511 a shout out on the changelog for getting this work started!)
The principle thing that drove this change was this todo:
sentry-javascript/packages/react/src/errorboundary.tsx
Lines 101 to 102 in 5b77377
Specifically we wanted to remove
null
as a valid state fromcomponentStack
, making sure that all exposed public API see it asstring | undefined
. React always returns astring
componentStack
from the error boundary, so this matches our typings more closely to react.By making this change, we can also clean up the
render
logic a little. Specifically we can check forstate.componentStack === null
to determine if a fallback is rendered, and then I went ahead and removed some unnecessary nesting.