Browser monitoring is a beta AppSignal Labs feature. The
@appsignal/browser package is published under the beta tag on npm, and its
configuration and API may still change between beta releases. Share feedback
in our Discord community.@appsignal/browser/react; there is no extra package to install.
Optional: React 16.8 or later, if you want to use the error boundary shipped with the package.
Catching render errors
captureError as a prop so the boundary can report errors it catches.
The boundary reports the caught error. Its onError callback also receives React’s component stack for your own handling. In this beta, that component stack is not included in ordinary error reports.
Recovering from an error
Pass a function asfallback to give the user a way to try again. It receives the error and a reset function, which clears the error and renders the children again:
Wrapping a single component
withErrorBoundary wraps one component, which is convenient for widgets that should fail without taking the page down:
Props
Place boundaries around routes or widgets with a useful fallback. A failed widget can then leave the rest of the page working. One boundary at the root catches everything, but replaces your whole application with the fallback.
Reporting the current route
Report the current route on initial load and after each navigation. Pass a pattern such as/orders/:id, not the resolved URL /orders/42. React Router route IDs and Next.js App Router’s usePathname() do not supply that pattern automatically. The React Router example uses a data router such as createBrowserRouter; render RouteReporter inside it.
RouteReporter from the matching route. For example, pass routeTemplate="/orders/[id]" from app/orders/[id]/page.jsx. usePathname() returns the resolved URL, such as /orders/42, so do not use it as the template.
Import your AppSignal setup before your router. The SDK and some routers both
patch
history.pushState, and the SDK composes with an existing patch rather
than replacing it. Loading the router first can leave client-side navigation
unreported.Reporting errors from event handlers and effects
An error boundary catches errors thrown during rendering. It does not catch errors thrown in an event handler, asetTimeout, or a rejected promise inside an effect. Uncaught ones reach window and are reported automatically. For the rest, report them yourself: