Skip to content

feat(devtools): intercept console errors for source map resolution#36781

Open
mehtahet619 wants to merge 1 commit into
react:mainfrom
mehtahet619:issue-36719-error-analyzer
Open

feat(devtools): intercept console errors for source map resolution#36781
mehtahet619 wants to merge 1 commit into
react:mainfrom
mehtahet619:issue-36719-error-analyzer

Conversation

@mehtahet619

@mehtahet619 mehtahet619 commented Jun 14, 2026

Copy link
Copy Markdown

Summary

Motivation:
Currently, React error boundaries catch errors but provide minimal context, making debugging difficult for common patterns. Furthermore, stack traces lack source map resolution in the DevTools console. This PR addresses Issue #36719 by explicitly identifying common error patterns and providing immediate, actionable fixes to improve the developer experience.

Changes made:

  1. Error Pattern Analyzer (packages/shared/ReactErrorAnalyzer.js): Created a utility to parse error strings and match them against common React pitfalls (e.g., null dereferences, invalid hook calls).
  2. DevTools Console Interception (packages/react-devtools-shared/src/backend/console.js): Intercepted component stack traces in the DevTools shell console overrides to explicitly resolve source maps.
  3. Reconciler Integration (packages/react-reconciler/src/ReactFiberErrorLogger.js): Injected the analyzer into defaultOnCaughtError and defaultOnUncaughtError strictly during __DEV__. It uses console.groupCollapsed to output highly visible recovery badges without cluttering the console.
  4. DevTools UI (packages/react-devtools-shared/src/devtools/views/ErrorBoundary/ErrorBoundary.js): Integrated the analyzer to display a "Suggested Fix" card directly inside the DevTools Error Boundary inspection view.

Fixes #36719

How did you test this change?

To ensure these changes are safe and do not impact production bundles, I verified the following:

1. Automated Checks:

  • Ran yarn prettier to ensure code formatting aligns with the repo standards.
  • Ran yarn lint to verify no linting regressions.
  • Ran yarn flow to ensure the new ReactErrorAnalyzer types correctly interface with the mixed error types in the Reconciler.
  • Ran yarn test and yarn test --prod to ensure the Reconciler and DevTools test suites pass successfully.

2. Manual Verification & UI Testing:

  • Zero Production Impact: Verified that the Reconciler changes are strictly wrapped in if (__DEV__) blocks.
  • Console Output: Triggered a "Cannot read properties of null" error and an "Invalid hook call" error in a local test app. Verified that console.groupCollapsed successfully renders the cyan/green "💡 React Recovery Suggestion" badge.
  • DevTools UI: Opened React DevTools and inspected an element wrapped in an Error Boundary that had caught an error. Verified the new suggested fix block renders cleanly above the component stack.
  • Source Maps: Verified that the console interceptor successfully appends the [Source Map Available] badge to stack trace lines when a valid .map file is fetchable.

@meta-cla

meta-cla Bot commented Jun 14, 2026

Copy link
Copy Markdown

Hi @mehtahet619!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Jun 14, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance error boundary with recovery suggestions and source map debugging

1 participant