feat(devtools): intercept console errors for source map resolution#36781
feat(devtools): intercept console errors for source map resolution#36781mehtahet619 wants to merge 1 commit into
Conversation
|
Hi @mehtahet619! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
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:
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).packages/react-devtools-shared/src/backend/console.js): Intercepted component stack traces in the DevTools shell console overrides to explicitly resolve source maps.packages/react-reconciler/src/ReactFiberErrorLogger.js): Injected the analyzer intodefaultOnCaughtErroranddefaultOnUncaughtErrorstrictly during__DEV__. It usesconsole.groupCollapsedto output highly visible recovery badges without cluttering the console.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:
yarn prettierto ensure code formatting aligns with the repo standards.yarn lintto verify no linting regressions.yarn flowto ensure the newReactErrorAnalyzertypes correctly interface with themixederror types in the Reconciler.yarn testandyarn test --prodto ensure the Reconciler and DevTools test suites pass successfully.2. Manual Verification & UI Testing:
if (__DEV__)blocks.console.groupCollapsedsuccessfully renders the cyan/green "💡 React Recovery Suggestion" badge.[Source Map Available]badge to stack trace lines when a valid.mapfile is fetchable.