RocketChat / RocketChat/EmbeddedChat

Missing React Error Boundaries - Application crashes on component errors

Open
#1,270 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
165
Forks
381
Avg merge
1d 2h
Merged PRs (30d)
1

Description

Problem

The EmbeddedChat React application currently has no Error Boundary components. This means that when any single component throws an error, the entire application crashes with a white screen, providing no graceful degradation or error recovery.

Impact

User Experience
  • 💥 Single component error crashes the entire chat widget
  • 💥 Users see blank white screen with no explanation
  • 💥 No way to recover without page refresh
  • 💥 Poor user experience and frustration
Developer Experience
  • 🔍 No error tracking or reporting infrastructure
  • 🔍 Difficult to diagnose production issues
  • 🔍 Component errors cascade to full app failure

Current State

Searched for Error Boundary: None found in codebase
Location: packages/react/src/ - No error boundary components exist

Proposed Solution

Implement React Error Boundary components at strategic points in the component tree:

1. Create ErrorBoundary Component
// packages/react/src/components/ErrorBoundary.jsx
import React from 'react';

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false, error: null, errorInfo: null };
  }

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

  componentDidCatch(error, errorInfo) {
    console.error('ErrorBoundary caught error:', error, errorInfo);
    // TODO: Send to error tracking service (Sentry, LogRocket, etc.)
  }

  handleReset = () => {
    this.setState({ hasError: false, error: null, errorInfo: null });
  };

  render() {
    if (this.state.hasError) {
      return (
        <div style={{ 
          padding: '20px', 
          textAlign: 'center',
          backgroundColor: '#fff3cd',
          border: '1px solid #ffc107',
          borderRadius: '4px'
        }}>
          <h3>⚠️ Something went wrong</h3>
          <p>We're sorry for the inconvenience. The chat encountered an error.</p>
          <details style={{ marginTop: '10px', textAlign: 'left' }}>
            <summary>Error details</summary>
            <pre style={{ 
              fontSize: '12px', 
              overflow: 'auto',
              backgroundColor: '#f5f5f5',
              padding: '10px',
              borderRadius: '4px'
            }}>
              {this.state.error?.toString()}
            </pre>
          </details>
          <div style={{ marginTop: '15px' }}>
            <button 
              onClick={this.handleReset}
              style={{ marginRight: '10px' }}
            >
              Try Again
            </button>
            <button onClick={() => window.location.reload()}>
              Refresh Page
            </button>
          </div>
        </div>
      );
    }

    return this.props.children;
  }
}

export default ErrorBoundary;
2. Wrap Application Root
// packages/react/src/views/EmbeddedChat.jsx (or main entry point)
import ErrorBoundary from '../components/ErrorBoundary';

const EmbeddedChat = () => (
  <ErrorBoundary>
    <RCContext.Provider value={...}>
      <ChatLayout>
        {/* Rest of app */}
      </ChatLayout>
    </RCContext.Provider>
  </ErrorBoundary>
);
3. Wrap Critical Sub-Components
// Isolate errors in specific components
<ErrorBoundary>
  <MessageList />
</ErrorBoundary>

<ErrorBoundary>
  <ChatInput />
</ErrorBoundary>

<ErrorBoundary>
  <UserInfo />
</ErrorBoundary>

This way, an error in MessageList won't crash ChatInput, etc.

Benefits

✅ Graceful error handling - app doesn't crash completely
✅ Better user experience - clear error message and recovery options
✅ Error isolation - component errors don't cascade
✅ Foundation for error tracking integration (Sentry, etc.)
✅ Better debugging in production

Implementation Effort

Estimated Time: 2-4 hours
Complexity: Low-Medium
Files Modified: 2-3 files
Testing: Should test error boundary catches errors correctly

Related

Acceptance Criteria

  • ErrorBoundary component created with fallback UI
  • Application root wrapped in ErrorBoundary
  • Critical sub-components wrapped in ErrorBoundary
  • Fallback UI shows clear error message
  • Recovery options provided (retry, refresh)
  • Error logging to console.error
  • (Optional) Integration with error tracking service

Discovered during: Comprehensive codebase analysis
Priority: HIGH - Affects all users when errors occur
Category: React Architecture / Error Handling

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting packages/react/src/views/EmbeddedChat.jsx (or the main entry point) and the existing components under packages/react/src/. Use the linked React Error Boundaries documentation to identify the root and critical-component integration points. Done means the root and selected components show a fallback with retry or refresh behavior, and errors are logged with console.error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.