Skip to content

Conversation

@sarthakNITT
Copy link
Contributor

@sarthakNITT sarthakNITT commented Dec 6, 2025

Description

  • Added a global React Error Boundary to prevent full white-screen crashes in production.
  • Without an error boundary, any runtime error inside a component (e.g., NavBar, Layout, page components) caused the entire app to break with no fallback UI.
  • The new ErrorBoundary now catches these errors and displays a friendly fallback screen with a refresh option.

Summary by CodeRabbit

  • New Features
    • Added an app-wide error boundary that displays a friendly fallback UI when unexpected errors occur.
    • Includes a "Refresh Page" button to let users quickly recover from an error state.
    • Wrapped the application root so the entire app benefits from centralized error handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 6, 2025

Walkthrough

Adds a React ErrorBoundary component and wraps the entire app root in pages/_app.tsx so runtime rendering errors show a fallback UI with a refresh action instead of crashing the app.

Changes

Cohort / File(s) Summary
Error Boundary component
components/ErrorBoundary.tsx
New React class component ErrorBoundary with ErrorBoundaryState { hasError: boolean }, constructor, static getDerivedStateFromError, componentDidCatch, and render that displays a fallback UI including a "Refresh Page" button when an error occurs.
App root integration
pages/_app.tsx
Imports ErrorBoundary and wraps the application root with it, moving existing app children inside the boundary.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review focus: lifecycle correctness (getDerivedStateFromError, componentDidCatch) and correct typing of props/state.
  • Verify fallback UI accessibility and that wrapping does not disrupt existing context/providers or props passed to the app.
  • Confirm logging in componentDidCatch follows project conventions.

Possibly related issues

Poem

🐇 I nibble bugs in code so bright,
I catch the crash and set things right.
A gentle button, refresh and play —
I patch the night and greet the day. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: added error boundary' clearly and directly summarizes the main change—adding an error boundary component to the application.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f866a5 and b6a1bd8.

📒 Files selected for processing (1)
  • components/ErrorBoundary.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/ErrorBoundary.tsx
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cypress-run

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify
Copy link

netlify bot commented Dec 6, 2025

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b6a1bd8
🔍 Latest deploy log https://app.netlify.com/projects/asyncapi-website/deploys/69340cb065c08d00081f1d19
😎 Deploy Preview https://deploy-preview-4689--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link

codecov bot commented Dec 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a677dc6) to head (b6a1bd8).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #4689   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines          799       799           
  Branches       146       146           
=========================================
  Hits           799       799           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Dec 6, 2025

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 47
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-4689--asyncapi-website.netlify.app/

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
pages/_app.tsx (1)

11-46: Global ErrorBoundary wrapper is solid; consider provider placement for future needs

Wrapping the whole tree with ErrorBoundary achieves the desired protection against white‑screen crashes while preserving existing layout and providers. If you later want the fallback UI to consume AppContext (e.g., theme, path, additional UX state), consider moving the boundary inside the provider:

<AppContext.Provider value={{ path: router.asPath }}>
  <ErrorBoundary>
    {/* existing tree */}
  </ErrorBoundary>
</AppContext.Provider>

No change is strictly required now; this is just a future‑proofing tweak.

components/ErrorBoundary.tsx (1)

1-49: ErrorBoundary behavior looks correct; tighten typings and logging for polish

The boundary implementation follows the usual React pattern and should work as intended. A few minor refinements you might consider:

  • Give props a concrete type instead of any, aligned with the class generics:
-export default class ErrorBoundary extends React.Component<React.PropsWithChildren, ErrorBoundaryState> {
-  constructor(props: any) {
+type ErrorBoundaryProps = React.PropsWithChildren<unknown>;
+
+export default class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
+  constructor(props: ErrorBoundaryProps) {
     super(props);
     this.state = { hasError: false };
   }
  • Make the lifecycle signatures explicit and typed, using unused‑param naming to satisfy linting:
-  static getDerivedStateFromError() {
+  static getDerivedStateFromError(_error: Error): ErrorBoundaryState {
     return { hasError: true };
   }

-  componentDidCatch(error: any, info: any) {
+  componentDidCatch(error: Error, info: React.ErrorInfo) {
     // eslint-disable-next-line no-console
     console.error('ErrorBoundary caught:', error, info);
   }
  • If you already have a central logging/monitoring utility (e.g., similar to how build runners use a shared logger.error), consider delegating to that here in addition to console.error so frontend runtime errors are captured consistently. Based on learnings, aligning with existing error-handling patterns will make ops/debugging easier across the stack.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a677dc6 and e1b2075.

📒 Files selected for processing (2)
  • components/ErrorBoundary.tsx (1 hunks)
  • pages/_app.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: sagarkori143
Repo: asyncapi/website PR: 4192
File: npm/runners/build-pages-runner.ts:7-14
Timestamp: 2025-06-19T13:51:27.459Z
Learning: In the AsyncAPI website build system, individual runner functions use try-catch blocks that rethrow errors to maintain consistent error boundaries, while the top-level orchestrator in npm/index.ts provides meaningful error logging with task-specific context using logger.error(`Error building ${taskName}:`, error). This separation of concerns allows for clean error handling at different architectural layers.
🧬 Code graph analysis (1)
pages/_app.tsx (1)
components/ErrorBoundary.tsx (1)
  • ErrorBoundary (7-49)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Redirect rules - asyncapi-website
  • GitHub Check: Header rules - asyncapi-website
  • GitHub Check: Pages changed - asyncapi-website
  • GitHub Check: cypress-run
  • GitHub Check: Lighthouse CI

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
components/ErrorBoundary.tsx (2)

3-11: Tighten props typing and avoid any / constructor boilerplate

Current class signature and constructor use loose typing and extra boilerplate:

  • React.PropsWithChildren is used without a concrete props shape.
  • constructor(props: any) defeats type-safety for props.
  • State can be initialized via a class field instead of a constructor.

You can simplify and get stronger typing like this:

-import React from 'react';
-
-interface ErrorBoundaryState {
-  hasError: boolean;
-}
-
-export default class ErrorBoundary extends React.Component<React.PropsWithChildren, ErrorBoundaryState> {
-  constructor(props: any) {
-    super(props);
-    this.state = { hasError: false };
-  }
+import React from 'react';
+
+type ErrorBoundaryProps = React.PropsWithChildren<{}>;
+
+interface ErrorBoundaryState {
+  hasError: boolean;
+}
+
+export default class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
+  state: ErrorBoundaryState = { hasError: false };

This keeps behavior identical while improving type safety and readability.

Please re-run the TypeScript compiler / ESLint after this change to ensure it matches your React 18 + TS config.


13-20: Use React’s typed error signatures for lifecycle methods

To align with React 18 typings and avoid any, you can tighten the error lifecycle signatures:

-  static getDerivedStateFromError() {
-    return { hasError: true };
-  }
-
-  componentDidCatch(error: any, info: any) {
+  static getDerivedStateFromError(_error: Error): Partial<ErrorBoundaryState> {
+    return { hasError: true };
+  }
+
+  componentDidCatch(error: Error, info: React.ErrorInfo) {
     // eslint-disable-next-line no-console
     console.error('ErrorBoundary caught:', error, info);
   }

This preserves behavior while matching React’s expected types and removes any from the public surface.

Please confirm against your installed @types/react version and adjust if its signatures differ.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1b2075 and 5f866a5.

📒 Files selected for processing (1)
  • components/ErrorBoundary.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PR testing - if Node project
components/ErrorBoundary.tsx

[error] 26-26: ESLint: 'spaced-comment' rule violated. Expected space or tab after '//' in comment.

⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cypress-run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants