You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Set the current fiber to the source of the error during error reporting (#29044)
This lets us expose the component stack to the error reporting that
happens here as `console.error` patching. Now if you just call
`console.error` in the error handlers it'll get the component stack
added to the end by React DevTools.
However, unfortunately this happens a little too late so the Fiber will
be disconnected with its `.return` pointer set to null already. So it'll
be too late to extract a parent component stack from but you can at
least get the stack from source to error boundary. To work around this I
manually add the parent component stack in our default handlers when
owner stacks are off. We could potentially fix this but you can also
just include it yourself if you're calling `console.error` and it's not
a problem for owner stacks.
This is not a problem for owner stacks because we'll still have those
and so for those just calling `console.error` just works. However, the
main feature is that by letting React add them, we can switch to using
native error stacks when available.
DiffTrain build for commit 2e540e2.
Copy file name to clipboardexpand all lines: compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-dev.js
@@ -11564,22 +11574,39 @@ function defaultOnUncaughtError(error, errorInfo) {
11564
11574
reportGlobalError(error);
11565
11575
11566
11576
{
11567
-
var componentStack = errorInfo.componentStack != null ? errorInfo.componentStack : '';
11568
-
var componentNameMessage = componentName ? "An error occurred in the <" + componentName + "> component:" : 'An error occurred in one of your React components:';
11569
-
console['warn']('%s\n%s\n\n%s', componentNameMessage, componentStack || '', 'Consider adding an error boundary to your tree to customize error handling behavior.\n' + 'Visit https://react.dev/link/error-boundaries to learn more about error boundaries.');
11577
+
var componentNameMessage = componentName ? "An error occurred in the <" + componentName + "> component." : 'An error occurred in one of your React components.';
11578
+
var errorBoundaryMessage = 'Consider adding an error boundary to your tree to customize error handling behavior.\n' + 'Visit https://react.dev/link/error-boundaries to learn more about error boundaries.';
11579
+
11580
+
{
11581
+
// The current Fiber is disconnected at this point which means that console printing
11582
+
// cannot add a component stack since it terminates at the deletion node. This is not
11583
+
// a problem for owner stacks which are not disconnected but for the parent component
11584
+
// stacks we need to use the snapshot we've previously extracted.
11585
+
var componentStack = errorInfo.componentStack != null ? errorInfo.componentStack : ''; // Don't transform to our wrapper
function defaultOnCaughtError(error$1, errorInfo) {
11573
11592
// Overriding this can silence these warnings e.g. for tests.
11574
11593
// See https://github.com/facebook/react/pull/13384
11575
11594
// Caught by error boundary
11576
11595
{
11577
-
var componentStack = errorInfo.componentStack != null ? errorInfo.componentStack : '';
11578
-
var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:'; // In development, we provide our own message which includes the component stack
11596
+
var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component." : 'The above error occurred in one of your React components.'; // In development, we provide our own message which includes the component stack
11579
11597
// in addition to the error.
11580
-
// Don't transform to our wrapper
11581
11598
11582
-
console['error']('%o\n\n%s\n%s\n\n%s', error, componentNameMessage, componentStack, "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + (errorBoundaryName || 'Anonymous') + "."));
11599
+
var recreateMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + (errorBoundaryName || 'Anonymous') + ".");
11600
+
11601
+
{
11602
+
// The current Fiber is disconnected at this point which means that console printing
11603
+
// cannot add a component stack since it terminates at the deletion node. This is not
11604
+
// a problem for owner stacks which are not disconnected but for the parent component
11605
+
// stacks we need to use the snapshot we've previously extracted.
11606
+
var componentStack = errorInfo.componentStack != null ? errorInfo.componentStack : ''; // Don't transform to our wrapper
0 commit comments