What Error Boundaries DON'T Catch: Async Code
You'll learn: Why errors in async code slip through error boundaries and how React's render-time catching works.
The Async Blindspot
Error boundaries are like safety nets under a trapeze, but only while performers are actively swinging. If someone falls after they've already left the trapeze and landed on the platform, the net can't help—it's no longer in position.
Similarly, error boundaries only catch errors during the render phase. Once rendering completes and control returns to the browser, React's error-catching mechanism is no longer active. Errors in asynchronous code—like setTimeout, requestAnimationFrame, promises, or async functions—happen after rendering finishes, so they bypass error boundaries entirely.
Where Error Boundaries Can't Help
function BrokenAsync() {
useEffect(() => {
// ❌ Error boundary won't catch this
setTimeout(() => {
throw new Error('Delayed explosion!');
}, 1000);
// ❌ Won't catch this either
fetch('/api/data')
.then(response => {
throw new Error('Promise rejection!');
});
// ❌ Or this
async function fetchData() {
throw new Error('Async function error!');
}
fetchData();
}, []);
return <div>Everything looks fine...</div>;
}
These errors crash the app or appear in the console, but the error boundary never sees them. The render already completed successfully—the errors happened later in the event loop.
The Core Limitation
Error boundaries hook into React's rendering lifecycle. Async callbacks execute outside that lifecycle, in browser APIs' territory. By the time setTimeout fires or a promise rejects, React has moved on.
Key Takeaway: Error boundaries only catch synchronous render-time errors. Handle async errors with .catch(), try/catch in async functions, or state-based error handling—error boundaries won't help with setTimeout, promises, or async code.