Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
53

Frontend System Design · Lesson 53 of 86 · 4 min

Global Error Boundaries in React

This topic separates candidates who build features from those who build resilient applications. Your answer shows if you think about production stability.

How to Prevent a Single Component from Crashing Your App

An uncaught JavaScript error during a React render will unmount the entire component tree. The user sees a blank screen. This is a critical failure.

Error Boundaries are React's solution. They are class components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of crashing.

An Error Boundary must be a class component. It works by defining one or both of these lifecycle methods:

  1. static getDerivedStateFromError(error): Runs first, after a child component throws. Its only job is to return a state object (e.g., { hasError: true }) to trigger a re-render that shows your fallback UI.
  2. componentDidCatch(error, errorInfo): Runs after getDerivedStateFromError. Use this for side effects, like logging the error and component stack (errorInfo) to an external service.

Here is a complete, production-ready Error Boundary. You should be able to write this from memory.

import React, { Component, ErrorInfo, ReactNode } from "react";

interface Props {
  children: ReactNode;
  fallback: ReactNode;
}

interface State {
  hasError: boolean;
}

class ErrorBoundary extends Component<Props, State> {
  public state: State = {
    hasError: false,
  };

  public static getDerivedStateFromError(_: Error): State {
    // Update state so the next render will show the fallback UI.
    return { hasError: true };
  }

  public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
    // You can log the error to an error reporting service here.
    // We'll cover this in the next lesson.
    console.error("Uncaught error:", error, errorInfo);
  }

  public render() {
    if (this.state.hasError) {
      return this.props.fallback;
    }

    return this.props.children;
  }
}

export default ErrorBoundary;

What Error Boundaries Don't Catch

This is the most common follow-up question in an interview. Knowing the limitations is as important as knowing the implementation.

Error Boundaries only catch errors that happen during React's "render phase": rendering, lifecycle methods, and constructors. They do not catch errors inside:

  • Event handlers (like onClick or onChange)
  • Asynchronous code (setTimeout, requestAnimationFrame callbacks, promises)
  • Server-Side Rendering (SSR)
  • The Error Boundary component itself

The interview question: "I put an Error Boundary around my component, but when I click a button that throws an error, the app still crashes. Why?"

Your answer: "Error Boundaries don't catch errors in event handlers. Those errors don't happen during a render lifecycle. You need to use a standard try/catch block inside the event handler itself to manage them."

For async code, use .catch() on your promises or async/await with try/catch.

Where to Place Your Boundaries

Strategic placement is key. You have a spectrum of choices, each with a trade-off.

At one end, a single "global" boundary high in your component tree. This is a good safety net for unexpected, application-breaking errors.

At the other end, granular boundaries around individual widgets or features. For example, wrap a third-party charting library, a complex form, or a single panel on a dashboard. If that one part fails, the rest of the page remains fully interactive.

Most mature applications use a hybrid approach:

  1. A "global" boundary wraps the main application layout or router view. This shows a generic "Something went wrong, please refresh" page.
  2. Specific boundaries wrap independent, non-critical parts of the UI. These can show a more contextual fallback, like "This widget could not be loaded."

The trap: Don't wrap your entire application in index.js. If your top-level boundary catches an error, the user sees a fallback UI but might lose access to a global navigation bar or a support chat widget that should always be available. A better "global" boundary lives inside your root App component, wrapping only the dynamic content area.

This flow shows what happens when a boundary is triggered.

Designing a Good Fallback and Recovery Experience

Simply showing a fallback UI is not enough. A good system allows for recovery and provides useful information for debugging.

Your fallback UI should not be a dead end. At a minimum, include a button to refresh the page. This is a simple but effective way for users to resolve transient issues.

For more complex scenarios, you can build a recovery mechanism. Pass a reset function to your ErrorBoundary that can be called from the fallback component. This function would reset the boundary's state (this.setState({ hasError: false })) and potentially clear any application state that led to the crash. This allows the user to "try again" without a full page reload.

Remember componentDidCatch gives you errorInfo, which contains the componentStack. This is a trace of which component threw the error. It's invaluable. Always log both the error and the full errorInfo object to your reporting service. This is the bridge between a user reporting "it broke" and you knowing exactly where to look.

Try it

Implement an ErrorBoundary component. Use it to wrap a simple component that has a button. Make the button's onClick handler set a state variable that causes the component to throw an error on its next render (e.g., if (this.state.shouldCrash) { throw new Error('Crashed!'); }). Verify that your fallback UI appears.

Next: We'll send the errors caught here to a real monitoring service in Error Reporting: Sentry and LogRocket.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Authentication Flows: OAuth and JWT

Next

Error Reporting: Sentry and LogRocket