ErrorBoundary (Recoverable Block Error Boundary)#
Overview#
ErrorBoundary is a Redux-connected React class component that wraps individual blocks during rendering. When a block throws an error, the boundary catches it and displays a fallback UI instead of crashing the entire page. The boundary automatically recovers when the user modifies the block structure in edit mode — allowing editors to fix a broken block without a page reload.
File: frontend/packages/volto-light-theme/src/components/Blocks/Block/ErrorBoundary.tsx
Props#
Prop |
Type |
Required |
Description |
|---|---|---|---|
|
|
No |
Human-readable block name shown in the error UI |
|
|
No |
Block UID, used for identification |
|
|
No |
Block type identifier |
|
|
No |
Whether the page is in edit mode |
|
|
No |
The block component to render |
Redux state (injected via connect)#
State path |
Description |
|---|---|
|
Current blocks map — changes trigger error reset |
|
Current layout — changes trigger error reset |
|
Page title — changes trigger error reset |
Behaviour#
Error capture#
getDerivedStateFromError() sets hasError: true when a descendant throws. componentDidCatch() logs the error and error info to the browser console. No external error reporting is performed.
Automatic recovery#
componentDidUpdate() compares the current blocks, blocksLayout, and title props against the previous values. If any of them changed, hasError is reset to false and the block re-renders normally. This allows an editor to:
See the error fallback UI.
Delete or modify the broken block.
Watch the error clear automatically — no reload required.
Fallback UI#
When hasError is true, the ErrorBoundaryMessage component is rendered. It displays the block name, type, and a note about edit mode.
Notes#
The error boundary catches errors in both view and edit mode — corrupt block data can be stored and rendered regardless of whether the user is editing.
Automatic recovery (resetting
hasErrorwithout a page reload) only works in edit mode, because a change toblocksorblocksLayouttriggers a re-render that resets the error state. In view mode, the fallback UI persists until the page is reloaded or navigated away from.Console errors are not suppressed — they remain visible in developer tools.
ErrorBoundarywraps each block in two places involto-light-theme: inRenderBlocks.jsx(view mode) and inBlock/Edit.jsx(edit mode).