Performance: Error boundaries with onErrorCaptured
MEDIUM IMPACT
This concept affects the rendering stability and responsiveness by catching errors in component trees without crashing the whole app.
import { defineComponent, onErrorCaptured } from 'vue'; const ErrorChild = defineComponent({ setup() { throw new Error('Oops!'); }, template: `<div>Child</div>` }); export default defineComponent({ components: { ErrorChild }, setup() { onErrorCaptured((err, instance, info) => { console.error('Captured error:', err); return false; // prevent further propagation }); }, template: `<div>Test with error boundary <ErrorChild /></div>` });
const MyComponent = { setup() { // No error boundary throw new Error('Oops!'); }, template: `<div>Test</div>` }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No error boundary | Full tree re-render on error | Multiple reflows if error causes remount | High paint cost due to full blank screen | [X] Bad |
| Using onErrorCaptured | Error caught locally, limited re-render | Single reflow for fallback UI | Low paint cost, stable UI | [OK] Good |