Course contentsShow
← React
Lesson 1320 of 2,39633. Error BoundariesFree lesson

Loading-to-Error Transition Design

Handle the UX flow from Suspense loading states into error boundaries when async operations fail.

Loading-to-Error Transition Design

What you'll learn: How to seamlessly transition from Suspense loading states into error boundaries when async operations fail, creating a smooth UX flow.

The Problem: Two Systems, One User Experience

You've learned about Suspense for loading states and Error Boundaries for catching errors, but what happens when a component starts loading (showing a Suspense fallback) and then fails? The user sees a loading spinner that suddenly disappears and becomes an error message. Without careful design, this transition feels jarring.

The Two-Phase Async Flow

When you fetch data with Suspense-enabled libraries:

  1. Loading Phase: Component suspends → Suspense boundary shows loading fallback
  2. Resolution Phase: Either success (render data) OR failure (throw error → Error Boundary catches it)

Think of it like ordering food: you see "Preparing your order..." (loading), then either your food arrives (success) or you get "Kitchen error, please retry" (error). The transition between these states needs to feel natural.

Design Principles

Preserve context during transitions: If your loading fallback shows "Loading user profile...", your error should say "Failed to load user profile" — not a generic "Something went wrong."

Visual continuity: Keep the error message in the same location as the loading spinner. Use similar visual weight and positioning.

Immediate feedback: Error boundaries catch errors as soon as they're thrown. Don't add artificial delays that make the transition feel sluggish.

Action parity: If your loading state had a "Cancel" option, your error state should offer "Retry" or "Go Back."

The user should understand these are two phases of the same operation, not disconnected UI states.

Key Takeaway: Design loading and error states as a continuous UX flow where the error boundary's fallback feels like a natural conclusion to what the Suspense fallback started, maintaining context, position, and offering appropriate next actions.