Skip to content

4.12: Create Error Boundary Component #93

@justin808

Description

@justin808

Overview

Create error handling UI (Client Component).

Parent Epic: #70
Priority: P1

Prerequisites

Next Issues (after this is complete)

  • None - this is a utility component

Acceptance Criteria

  • app/javascript/components/ErrorBoundary.tsx created (Client Component)
  • Uses 'use client' directive
  • Catches rendering errors in child components
  • Shows user-friendly error message
  • "Try again" button to attempt reload
  • Logs errors for debugging
  • CSS module styling

Implementation Notes

'use client';

import { Component, ErrorInfo, ReactNode } from 'react';

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

interface State {
  hasError: boolean;
  error?: Error;
}

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

  static getDerivedStateFromError(error: Error): State {
    return { hasError: true, error };
  }

  componentDidCatch(error: Error, errorInfo: ErrorInfo) {
    console.error('Error caught by boundary:', error, errorInfo);
  }

  render() {
    if (this.state.hasError) {
      return this.props.fallback || (
        <div>
          <h2>Something went wrong</h2>
          <button onClick={() => this.setState({ hasError: false })}>
            Try again
          </button>
        </div>
      );
    }
    return this.props.children;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    HN-RSCHacker News RSC DemoRSCReact Server Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions