@molecule/app-root-error-boundary-react
Feature · error-boundary · App (browser) · v1.1.1 · Apache-2.0
Top-level React error boundary that logs render errors via the bonded app logger and shows a minimal localized recovery surface
npm install @molecule/app-root-error-boundary-reactHow it works
@molecule/app-root-error-boundary-react is a ready-made error-boundary feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import type { ReactNode } from 'react'
import { RootErrorBoundary } from '@molecule/app-root-error-boundary-react'
function AppRoot({ children }: { children: ReactNode }) {
return <RootErrorBoundary>{children}</RootErrorBoundary>
}Works with: @molecule/app-i18n, @molecule/app-logger, @molecule/app-react, @molecule/app-ui, @molecule/app-ui-react
Reference
Top-level React error boundary that catches render errors, logs them via
the bonded @molecule/app-logger, and shows a minimal localized fallback
message through useTranslation() from @molecule/app-react.
Exports <RootErrorBoundary> (class component; children is the only
prop). Mount it directly under your routing root so it covers the whole
route tree.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import type { ReactNode } from 'react'
import { RootErrorBoundary } from '@molecule/app-root-error-boundary-react'
function AppRoot({ children }: { children: ReactNode }) {
return <RootErrorBoundary>{children}</RootErrorBoundary>
}
Type
feature
Installation
npm install @molecule/app-root-error-boundary-react @molecule/app-i18n @molecule/app-logger @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
npm install -D @types/react
API
Classes
RootErrorBoundary
Top-level React error boundary that catches render errors, logs them via
the bonded @molecule/app-logger, and falls back to a minimal recovery
surface localized through useTranslation() from @molecule/app-react.
Use this directly under your routing root so it covers the whole route tree.
class RootErrorBoundary extends Component<Props, State> {
override state: State = { hasError: false }
/**
* Transitions the component into error state when a render error is caught.
*/
static getDerivedStateFromError(): State {
return { hasError: true }
}
/**
* Logs the caught render error and its component stack via the bonded logger.
*/
override componentDidCatch(err: Error, info: ErrorInfo): void {
logError(err, info.componentStack ?? '')
}
/**
* Renders children normally, or a localized fallback UI when an error has been caught.
*/
override render(): ReactNode {
if (this.state.hasError) {
return <RootErrorFallback />
}
return this.props.children
}
}
Injection Notes
Requirements
Peer dependencies:
@molecule/app-i18n^1.0.1@molecule/app-logger^1.0.1@molecule/app-react^4.4.0 || ^5.0.0@molecule/app-ui^1.0.1@molecule/app-ui-react^4.4.0react^18.0.0 || ^19.0.0
Runtime Dependencies
-
@molecule/app-i18n -
@molecule/app-logger -
@molecule/app-react -
@molecule/app-ui -
@molecule/app-ui-react -
react -
The fallback UI styles itself via
getClassMap()— if no ClassMap is bonded the boundary itself throws while rendering the fallback. EnsuresetClassMap()runs during bootstrap, before anything can error. -
There is no retry/reload action — the fallback is a static message (key
error.unknown). Wrap or fork when you need a recovery button. -
React error boundaries catch RENDER errors only — not event handlers, async code, or server-side rendering errors.
-
The fallback translates through
useTranslation(), so it re-renders in the new language after a locale switch. NoI18nProvideris required: outside one it reads the bonded@molecule/app-i18nprovider, and without locale registration it falls back to English. Translations:@molecule/app-locales-root-error-boundary.
Translations
Translation strings are provided by @molecule/app-locales-root-error-boundary.