Sitecore / jss

Software development kit for JavaScript developers building web applications with Sitecore Experience Platform
https://jss.sitecore.com
Apache License 2.0
263 stars 275 forks source link

[sitecore-jss-react] Introduce ErrorBoundary to serve as error handling per component #1786

Closed yavorsk closed 6 months ago

yavorsk commented 7 months ago

Description / Motivation

This PR introduces ErrorBoundary component. All rendered components are wrapped with it and will catch client or server side (uses < Suspense />) errors from any of its children, display appropriate message and prevent the rest of the application from failing. It accepts and can display custom error component and loading message if it is passed as a prop to parent Placeholder. Note that ErrorBoundary will not catch errors for:

If an error occurs in development mode or during page editing the ErrorBoundary will display error message with the name of the faulty component and the error's message. If we are in production mode and the error happens not in editing mode ErrorBoundary will display generic error message without providing additional information about the error and the component. If Custom error component has been provided to the Placeholder showing it will take precedence over the above scenarios.

Testing Details

Types of changes