compacto-ui

Search documentation

Jump to a page or a component.

ErrorBoundary

Catches render errors so one broken widget doesn't take the view.

Preview

Rendering normally.

Installation

No install — ask an AI agent to copy this component from registry.json.

import { ErrorBoundary } from "@/components/ui/error-boundary";

Notes

  • A class component, unlike everything else here: React exposes no hook equivalent of getDerivedStateFromError.
  • Does not catch async, event-handler or rAF errors — React never routes those through a boundary. Those need a window-level handler, which belongs in your app: which async failures are benign is an application question, and a library that swallowed them would hide real bugs from you.
  • resetKeys clears the error when an input changes, so recovery happens on its own once the thing that broke it changes.
  • Derives ${testId}-error-fallback and ${testId}-retry-button.

Props

The props worth knowing. Everything else passes straight through to the underlying element, including className, which is merged last so it always wins.

PropTypeDefaultDescription
fallback(error, reset) => ReactNode—Full replacement for the default UI. When given, message / retryLabel / className are unused.
resetKeysunknown[]—Values that, when changed, clear the error.
onError(error, info) => void—Side effect on catch — logging or telemetry.
messagestring"Something went wrong rendering this view."Copy for the default fallback.
retryLabelstring"Retry"Label for the default fallback's retry button.