-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
feat(react-router): add unstable_onError
prop to RouterProvider
for client side error reporting
#14162
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
Conversation
🦋 Changeset detectedLatest commit: 3d7dcee The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
let logErrorsAndSetState = React.useCallback( | ||
(newState: RouterState) => { | ||
setStateImpl((prevState) => { | ||
// Send loader/action errors through handleError | ||
if (newState.errors && unstable_handleError) { | ||
Object.entries(newState.errors).forEach(([routeId, error]) => { | ||
if (prevState.errors?.[routeId] !== error) { | ||
unstable_handleError(error); | ||
} | ||
}); | ||
} | ||
return newState; | ||
}); | ||
}, | ||
[unstable_handleError], | ||
); |
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.
Log loader
/action
errors every time we set state which should keep this synced with "report errors that are surfaced in the UI". This switches to use the setState
callback function too so it can compare to prior state.errors
to avoid duplicate reporting of errors on subsequent state updates (like calling a fetcher from an error boundary).
componentDidCatch(error: any, errorInfo: React.ErrorInfo) { | ||
if (this.props.unstable_handleError) { | ||
// Log render errors | ||
this.props.unstable_handleError(error, errorInfo); |
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.
Log <Await>
render errors
Object.defineProperty(resolve, "_error", { get: () => error }), | ||
(error: any) => { | ||
// Log promise rejections | ||
this.props.unstable_handleError?.(error); |
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.
Log <Await>
promise rejections
packages/react-router/lib/hooks.tsx
Outdated
); | ||
componentDidCatch(error: any, errorInfo: React.ErrorInfo) { | ||
if (this.props.unstable_handleError) { | ||
this.props.unstable_handleError(error, errorInfo); |
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.
Log render errors
Alpha release created:
git log --pretty=oneline [email protected] |
unstable_onError
prop to RouterProvider
for client side error reporting
Co-authored-by: Michaël De Boey <[email protected]>
Alpha release created:
git log --pretty=oneline [email protected] |
🤖 Hello there, We just published version Thanks! |
Implements: #12958
RFC: #9881
API:
This is a client-side version of the
entry.server
handleError
function to be used for client-side error reporting. This has 2 main advantages over the current approach of trying to log fromErrorBoundary
:errorInfo
prop fromcomponentDidCatch
for render errors