# Async Component Error Handling
## Rule
Always configure error handling for async components using `errorComponent` and/or `onError` callback. Without proper error handling, failed component loads can leave the UI in an undefined state with no user feedback.
## Why This Matters
Network failures, timeouts, and server errors are common in production. Without error handling, users see blank spaces or broken UIs with no indication of what went wrong or how to recover.
## Bad Code
```vue
```
```vue
```
## Good Code
```vue
```
```vue
```
```vue
```
## onError Callback Parameters
The `onError` callback receives four arguments:
| Parameter | Type | Description |
|-----------|------|-------------|
| `error` | `Error` | The error that caused the load to fail |
| `retry` | `Function` | Call to retry loading the component |
| `fail` | `Function` | Call to give up and show errorComponent |
| `attempts` | `number` | Number of load attempts so far |
## Key Points
1. Always provide an `errorComponent` for production applications
2. Use `timeout` to prevent indefinite loading states
3. Consider retry logic with `onError` for transient network issues
4. The `delay` option (default 200ms) prevents loading flicker on fast networks
5. Use the fallback pattern (`.catch()` in loader) when you want a seamless degradation
## SSR Warning
Using `onError` with SSR can cause issues in some configurations, potentially leading to infinite loading. Test thoroughly in SSR environments.
## References
- [Vue.js Async Components Documentation](https://vuejs.org/guide/components/async)
- [Handling Async Components' loading errors](https://awad.dev/blog/handling-async-component-loading-errors/)